Archive for May, 2006

Serving static files in Django (in development mode)

I got stuck today while I was trying to have the javascripts running with Django.After reading Django document: How to serve static files , I finally figure out the step by step procedure:

step 1.

put this in urls.py

r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),

so now the file /path/to/media/js/myscript.js will be made available at the URL /site_media/js/myscript.js.

step 2.

In the template file, change the javascript directive line to <script src=”/site_media/js/myscript.js” type=”text/javascript”></script>

That’s it.However,there is a “big, fat disclaimer” in the document which said ”

Using this method is inefficient and insecure. Do not use this in a production setting. Use this only for development.

For information on serving static files in an Apache production environment, see the Django mod_python documentation.” … I think I need to spend some time on this topic in the future.

Setting up Django in Dreamhost

Jeff Croft wrote up a very good tutorial showing how to setup Django application in Dreamhost. For those who are already familiar with settiong up a subdomain and creating a MySQL database in Dreamhost, the subsections to notice are:

1. Set environrmnt variables in ~/.bash_profile:

export PATH=$PATH:$HOME/path/to/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/path/to/django_src:$HOME/path/to/django_projects
export DJANGO_SETTINGS_MODULE=myproject1.settings:myproject2.setting

2.Install and configure FastCGI

3.Set up mod_rewrite

4.Install Django’s built-in administrative interface