djangostatic-contentdjango-flatpages

Django Direct_to_template or flatpages


Building a django app with some mostly static pages at the front of the site e.g. about.html faq.html

that kind of thing

I was looking at how urls.py work and I created this.

('(.+\.html)$', direct_to_template),

It seems to do exactly what I needed. Now for any new .html page I add to the root of my templates folder it just works. templates/about.html templates/faq.hml

I can also use things like this in my templates

{% include "_menu.html" %}

Now someone has kindly pointed out Django FlatPages and suggested maybe I use them instead. If I'm not connecting to the db are there any disadvantages to the way I'm doing it.

Seems to me like its a better way to do it than FlatPages because it uses the db and isn't quite as elegant (haven't actually used flatpages in practice though)


Solution

  • I would suggest moving one step further. If your static content doesn't change frequently and doesn't make use of Django's templates then don't use Django to serve them. Use a light weight server such as Nginx instead.

    If you do make use of Django's template features without requiring any dynamic content from the database then you can stick with direct_to_template.