66
With the class-based views in newer Django versions, one can use this in urls.py:
from django.views.generic import TemplateView
url(r'^about',
TemplateView.as_view(template_name='path/to/about_us.html'),
name='about'),
52
Bypassing views to render a static template, add this line in “urls.py”. For example “About Us” page could be
(r'^about', 'django.views.generic.simple.direct_to_template', {'template': 'path/to/about_us.html'}),
- [Django]-Page not found 404 on Django site?
- [Django]-Django Invalid HTTP_HOST header: 'testserver'. You may need to add u'testserver' to ALLOWED_HOSTS
- [Django]-Django: Record with max element
- [Django]-How can I render a ManyToManyField as checkboxes?
- [Django]-Proper way to handle multiple forms on one page in Django
- [Django]-Success_url in UpdateView, based on passed value
2
If you want to make a static page the flatpages is a good choice. It allows you to easily create static content. Creating static content is not harder than creating a view really.
- [Django]-Django equivalent of SQL not in
- [Django]-Django 1.7 upgrade error: AppRegistryNotReady: Apps aren't loaded yet
- [Django]-What is actually assertEquals in Python?
1
On Django 2.2.6, loosely following David’s answer, I added the path in urls.py:
from django.views.generic import TemplateView
urlpatterns = [
.... .... ....
path('about',
TemplateView.as_view(template_name='path/to/about_us.html'),
name='about'),
And I needed to adjust settings.py to specify the template directory:
TEMPLATES = [{
... ... ...
'DIRS': [os.path.join(BASE_DIR, 'template')],
Then I saved the actual content in template/path/to/about_us.html
- [Django]-How do I separate my models out in django?
- [Django]-RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated
- [Django]-Django models: get list of id
Source:stackexchange.com