Serving static files in development with Django

April 23rd, 2009 by Nick

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")}),
    )

Django gotcha: passing a request context

March 31st, 2009 by Nick

Backup dreamhost database

December 16th, 2008 by Nick

Deploying rails app with mod_rails on dreamhost

November 28th, 2008 by Nick

Agile2008 on FriendFeed - Viral Campaign

August 5th, 2008 by Nick

Agile2008 on FriendFeed, an experiment

July 29th, 2008 by Nick

Ruby’s Operator Expressions and Message Expressions using Operator Methods Yield Different Results

February 21st, 2008 by Koen

Distributed User Acceptance Test Session

January 25th, 2008 by Koen

Installing Ruby In Your Home Folder On Dreamhost

November 22nd, 2007 by Nick

Multi-lingual site in Drupal

September 20th, 2007 by Nick

Close
E-mail It
Socialized through Gregarious 42