Question

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)

Was it helpful?

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.

OTHER TIPS

If you're ok editing template files directly and manually adding new ones to your urls.py file, then stick with what you've got. Flatpages is useful if you want to be able to edit page content from the admin interface or any web-based editing tool you might care to design, or perhaps more to the point: if you want non-technical users to be able to edit the content.

One advantage to using FlatPages is that you can use the Django templates to for headers, sidebars, footers (to maintain a consistent site appearance) while still using mostly plain HTML for the page content. That is offset by the need to store the page content in a database table.

My advice? If what you're doing is meeting your needs, stick with what works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top