Django and Dreamhost, Take 2

After installing my own custom Python build, I went back and tweaked how Django ran on my Dreamhost account. My previous Django installation experience is still mostly valid. I just figured I could "upgrade" the installation to take advantage of Python 2.5 and eggs.

I installed three eggs to get Django running

# For Django
python ez_setup.py MySQL-python
python ez_setup.py http://www.saddi.com/software/flup/dist/flup-r2030.tar.gz
python ez_setup.py http://www.djangoproject.com/download/0.95/tarball/

The first was mySQL support; second was for Django's built-in fcgi support; and finally Django itself.

I had a second goal in this upgrade. I wanted to partition off the "/-/" subtree (For example, http://example.com/-/admin/) for Django, instead of using the full subdomain. I had to make a couple of changes to the project's urls.py file (to handle the '-') and to the .htaccess file:

# urls.py change example for the admin application.
(r'^-/admin/', include('django.contrib.admin.urls')),

The .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^-$ /-/ [R]
RewriteRule ^-/(.*)$ /_/mysite.fcgi/-/$1 [QSA,L]
</IfModule mod_rewrite.c>

And finally, a new mysite.fcgi script found in the /_/ directory (notice that it's an underscore, not a dash):

#!/home/user/bin/python/bin/python
import sys, os

# Switch to the directory of your project. (Optional.)
# os.chdir("/home/user/myproject")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])