views:

40

answers:

3

Ok, fairly new to Django so bare with me.

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)

any thoughts?

A: 

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.

mazelife
I think you are missing the point.. with this solution i don't have to edit the urls.py file at all. if i want a new file say example.com/terms.html all i have to do is create the new html file and save it to my templates folder.. done. I do understand the CMS part alright though.
Derek Organ
Apologies, I read that a bit too fast. Sounds like your way is fine then; no point in over-engineering something.
mazelife
+1  A: 

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.

Manoj Govindan
agh.. so thats +1 for my approach. :)
Derek Organ
A: 

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.

Craig Trader