Forums

Setting debug=False in django settings

Hi there,

Are there any forum posts can you point me to about serving staticfiles through pythonanyhwere? The django documentation seems to be geared towards other types of web hosting..I.e., when I set debug=False django is designed to no longer serve the staticfiles.

Take a look at this thread, and possibly also the very end of this one. The upshot is that you can currently use /var/www/static to have static files served directly through the webserver (not through Django). This is the recommended state of affairs for production websites because it's considerably more efficient, which is presumably why Django doesn't serve static files outside debug mode.

Apparently a more elegant approach to serving static content from user home directories is coming Real Soon Now. (^_^)

Great thanks. Do I need to add anything to my urls file?

No, Django isn't involved in serving file from the static directory at all, I believe nginx serves them directly. This means it should work for all frameworks not just Django.

Bear in mind, though, that there will be unlimited public access to the files - if you want to do access control then you'll need to persuade Django to serve them. You could control access to the URLs of the static files within Django (i.e. control who you give the links to), but there's nothing to stop people guessing the URLs.

Of course, you might not care about controlling access (many websites are totally public, after all), but I thought it was worth mentioning because it's something I've run into in the past.

Note to PAW staff: whenever you sort out the long term solution for static file serving via nginx it might be worth thinking about access control - the most promising possibility I've found is the static link module, although I haven't tried it myself.

Thanks, Cartroo -- another useful link for us :-)

The proper static file support is something we're adding after support for multiple web applications -- because if we'd done static files first then we'd have had to rewrite it as part of the web app changes. The good news is, we pushed the multiple web app code into our integration farm on Friday, so it's looking good for a release next week :-)

You're welcome! I just wish I had time to try these things myself more thoroughly before passing them on, because I know that's typically the most time-consuming part. Still, I figure it's worth at least sharing the third party options I'm aware of in case it saves you rolling your own.

Of course most of the fun is generally in rolling your own - one of the great conflicts in software engineering... Not that I've ever been tempted to write my own compiler, mind you. (^_^)