Django doesn't serve static content, is this a major downer or what?
4 comments
Why would your want your app server to serve static content!?
Point apache or whatever traditional web server, which is really good at serving static ocntent in an efficient manner, at it and be done with it.
To answer your question: No, I don't think serving static content should be something your web framework does. It sounds inefficient and less flexible to me. For example, if I have a web server in front of the framework, I have more control over caching and load balancing.
Point apache or whatever traditional web server, which is really good at serving static ocntent in an efficient manner, at it and be done with it.
To answer your question: No, I don't think serving static content should be something your web framework does. It sounds inefficient and less flexible to me. For example, if I have a web server in front of the framework, I have more control over caching and load balancing.
for local development, i think its perfectly reasonable to assume a built-in development server can handle serving static content. in fact, if it didn't, i'd be a little sour -- it can serve dynamic content, so why not static?
and, not everyone wants to run apache or nginx or lighty on their dev machines.
and, not everyone wants to run apache or nginx or lighty on their dev machines.
django opts not to serve static content by choice, but it can easily be made to. adding a line to your urlconf associating the path to your static media with an out-of-box view is all thats required. full documentation and more info about why the framework doesn't serve static content by default is available here: http://docs.djangoproject.com/en/dev/howto/static-files/
It's a conscious decision. After all, why would you reinvent static content serving when Apache, lighttpd, and nginx all have solved this problem extremely well? It's much lower overhead to just let the purpose-built native-code server do this instead of bolting it into your web framework.
And allows you more flexibility with caching and load balancing too.
What do you mean a 'hack' ?
Here's how to do it:
Here's how to do it:
import os
OUR_ROOT = os.path.realpath(
os.path.dirname(__file__)
)
MEDIA_ROOT = os.path.join(OUR_ROOT, 'media')
MEDIA_URL = '/static/'
Drop that in to your 'settings.py' and you should be fine.
However, when I actually started to work on serving complex webpages. I discovered that DJANGO DOES NOT SERVE STATIC CONTENT. This includes css | js | img files. Even in development mode, you have to create a hack around to do this.
In rails, this would have being a simple placement in the public folder. I feel the lack of this feature is something no modern web framework should have. Do you think a webserver should include the ability to serve static content?