I'm not sure how common it is to run Django without templates of any kind, but our project recently had reason to do so. Turning off all the template related settings is relatively straight forward if you follow the settings documentation from the Django site.
Django still expects certain templates to exist though. For example, when it can't find a page, it expects there to be a 404.html Django template. I didn't want any templates at all, so to overcome this, I handled all incoming urls with a default view that always returned a certain string when there was a problem. Hooking up the view in the urls.py file involved putting a regular expression at the end of the list like this r'^.*'. Be sure that it's at the end, otherwise it will always be called for urls you are expecting.
Another way to do this is to define the default handler for 404 errors. Adding a line like this to your urls.py will override the default 404 handler.
handler404 = 'project.application.views.default404'
You can do the same with server errors, which catching all the urls as above wouldn't help you with.
handler500 = 'project.application.views.default500'
More on this method is here.
2009-02-02
Subscribe to:
Post Comments (Atom)
0 responses:
Post a Comment