Django in HostMonster

With effort, I finally put one of my Django applications online.  The situation is that HostMonster does provide the Python intepreter, but seems we are not suppose to use Python as a web app language because the Python is version 2.3, and no framework module is pre-installed.  So I first installed the Dejango package to ~/.python, and did some searching to find this.  According to this document, I copied my Django app to /my-web-root/latrine in which “latrine” was the name of my app, and wrote /my-web-root/latrine/.htaccess as

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ latrine.fcgi/$1 [QSA,L]

And wrote a latrine.fcgi script:

#!/usr/bin/env python
# -*- mode: python; -*-

import sys, os

# Add a custom Python path.
sys.path.insert(0, "/my-web-root")
sys.path.insert(0, "/my-home/.python")

# Switch to the directory of your project. (Optional.)
# os.chdir("/my-web-root/latrine")

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

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

And happily entered http://darksair.org/latrine/ in my browser, which displayed a very friendly 500 internal error.  I was glad that I myself finally made a famous 500 error.  After the excitement, I tried to locate the fault.  I manually ran the fcgi script in a remote shell, and it was all right (Ok, except tons of Python trackbacks.  But that was another thing.).  So I decided that the problem was in .htaccess, which I sadly know nothing about...  After some painful research I notied that the fastcgi module in HostMonster was actually fcgid-script instead of fastcgi-script.  After fixing that in .htaccess, and did some simple Python debug, Latrine Live was online.

comments powered by Disqus