Sunday, December 26, 2010

Serving static files in Django

This is how to serve static files from the default Django python web server

1. add the following lines to your urls.py file


#!/usr/bin/python

urlpatterns = patterns('',
...

(r'^your_dir/(?P.*)$', 'django.views.static.serve', {'document_root': '/path/to/your/static/files/'}),
#(r'^data/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/django/testproject/data/'}),
...

)

No comments: