Last month, Dreamhost announced their new support for Django using Passenger WSGI. (Instructions are posted here.)
The process is pretty simple. First, I setup a new subdomain for the app. One can probably setup a Django app using a subfolder of an existing domain, but I haven’t explored that yet. As instructed, I setup the subdomain with the Passenger option.
Next, I added a database for the domain. Nothing tricky or new here.
The final step in their instructions was to download and run the setup script. I was a little confused about where I should run it, as the instructions referred to the “directory for the application”. After a little experimentation, I figured out that I should be in the root directory for the subdomain (created when the subdomain was created), which has the /public
directory in it. The script asks a few questions and runs quickly. At the end, I had a settings.py
and urls.py
, the database was initialized, and the admin app was ready to go. If the programmer is starting a new application, this is a good place to start.
However, I have already been working on my app on my laptop, and I wanted to copy it to the server. Since I’m using Subversion to store my code, it was easy to use the svn co
command to copy the files over – after I first moved the recently created settings.py
to a safe location.
I copied the database and media location entries from the new settings.py
into the existing version with my application. I typed in the URL and was ready to go.
EXCEPT … I forgot about a problem I hit when installing another Django app on Dreamhost using the older FastCGI configuration. It seems that I have to qualify a couple of the file names in settings.py
and urls.py
to help Django find them. Specifically, the applications listed in INSTALLED_APPLICATIONS
need to have the project name appended to the beginning. The same for imported URL files. Those two changes did the trick.
UPDATE: To solve this path problem, I added this line to passenger_wsgi.py:
sys.path.append(os.path.join(os.getcwd(),'project')) - where 'project' is the project name
EXCEPT … my application uses Python constructs (in this case, decorators) that were added after version 2.3, which is the default on my Dreamhost server. With my earlier Django install, I had installed Python 2.5 in my /bin
folder and was able to directly the server to use that version. Even after following the instructions I found in a discussion attached to the wiki page, I was not able to get this to work. The command I added to pasenger_wsgi.py
was:
if sys.version < "2.5": os.execl("/home/gentryadmin/bin/python", *sys.argv)
Instead of using the new version, I see a screen telling me I have hit an Internal Server Error. I've yet to find a log file that has information on this error.
I can change the decorator code to Python 2.3 friendly syntax, but this problem will get in the way when/if I want to use other Python/Django applications or modules. Hopefully, I can get this fixed.
Any ideas or thoughts? Please leave a comment below.