Django urls straight to html template


Learning django & python.

Just set up a new site after doing the tutorial. Now for arguments sake say I want to add a bunch of About us, FAQ basic html pages with very limited dynamic elements do you go ahead and write a new line in my file for each page? or is their some neat way to say map all * *.html to the relevant .html file directly?

In general even if it does require a view will I have to write a new line in the file for every page?

8/4/2010 4:58:21 AM

Accepted Answer

As long as there is some uniquely identifying section in the URL, you will not need to create an entry in for each direct-template url.

For example, you could say that all urls ending in ".html" are referencing a direct file from the templates.

urlpatterns = patterns('django.views.generic.simple',
    (r'(.+\.html)$', 'direct_to_template'),
    # ...

Take a look at for details.

5/17/2012 6:58:56 PM

Currently the best way to do this is using TemplateView from generic class-based views:

from django.views.generic.base import TemplateView

url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow