What is this? From this page you can use the Social Web links to save Serving static files in development with Django to a social bookmarking site, or the E-mail form to send a link via e-mail.

Social Web

E-mail

E-mail It
April 23, 2009

Serving static files in development with Django

Posted in: django, gotcha

Another small gotcha that took me some time to figure out.

I noticed my stylesheets and javascript weren’t loading during development. (note, I’m doing a small fun application starting from plain django, not pinax, like the previous thingy I was doing.) I did check my settings file to see if the MEDIA_ROOT was properly set, and it was. Still I got 404’s for stylesheets and javascripts.

After some triple checking paths and all, I went to google and found a nice explanation in the django documentation.

Basically, what you need to do is include the follwing url configuration in your root urls.py.

Be sure to read the documentation I mentioned above and the remarks they make about using this method only for development.

Hope this helps.

1
2
3
4
5
if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': os.path.join(os.path.dirname(__file__), "site_media")}),
    )

Return to: Serving static files in development with Django