Misty thoughts

19May/084

Installing Django on Dreamhost

Dreamhost appears on the django site as one of the django friendly hosting services. Unfortunately, dreamhost does not officially support django. It does not have mod_python installed. Django is instead deployed using FastCGI. Hopefully sometime in the future mod_python will be added. There are a few good guides I have found, that explain how to setup django on a dreamhost account:

  • Jeff Croft has a good guide on his blog
  • Gordon Tillman also has a good informative page
  • The dreamhost wiki also has a guide
  • Between the three of them you can probably find all the information needed for installing django for use on a dreamhost account. I will not repeat what they explain but instead add some from my own experience.

    Python

    Dreamhost, at the moment of writing, is running python 2.4. Luckily it is possible for you to locally install python. I highly recommend it as it will enable you to setup the python environment exactly the way you want it, and it will make it easier to upgrade to future versions of python.


    cd ~/soft
    wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
    tar xvfz Python-2.5.2.tgz
    cd Python-2.5.2
    ./configure --prefix ~/install/dir --enable-shared
    make
    make install

    Where ~/install/dir is the directory you want python installed in. I followed dreamhost's Unix account setup guide and installed it under run. I recommend you do to, as it is easier to have full control over you /usr/local.
    Also adding setuptools makes future installs easier


    cd ~/soft
    wget http://peak.telecommunity.com/dist/ez_setup.py
    ~/path/to/yourpython/python ez_setup.py

    This will add the easy_install script which will simplify adding packages to your own python install. The final step is adding the new MySQLdb package


    cd ~/soft
    svn co https://mysql-python.svn.sourceforge.net/svnroot/mysql-python/trunk/MySQLdb MySQLdb
    easy_install MySQLdb

    This is assuming easy_install is in your PATH. If it is not it needs to be added.

    Your now ready to install django using your very own Python installation. That is detailed enough so I will move to two problems I met after the installation.

    Post Installation Problems

    I met with two problems that had frustrated me for a few hours. To save you the future installer some pain here they are in case you experience something similar

    syncdb after admin activation: This should have been very obvious to me but for some reason it escaped me. After enabling the admin page you must run django-admin.py syncdb in your project home page. What happened was that I ran it before I enabled the admin application. This lead to the creation of the needed tables in the MySQL database, but no tables for the admin application. After enabling the admin application, more tables need to be created to accommodate the new application data. The errors I got gave me the impression that there was an error in the MySQLdb egg, so I reinstalled it, then tried to find some workaround. Eventually I realized that I'm just missing the admin tables.

    .htacess: This was the real mind bender. I kept getting an internal server error saying that it reached maximum internal allowed redirects. It was obviously a configuration error so I compared my .htaccess with that of the guides and it looked the same. So I looked else, but I kept coming back to the conclusion it has to be in the .htaccess. Yet no matter how often I looked at it I couldn't find what was wrong. I need to point out that I am no expret when it comes to apache and that maybe if I knew more about it this would have been simple, but I didn't so I got some gray hairs before I realized I'm missing a space between the - and the [L]. A bloody white space! I was feeling furious and incredibly stupid at the same time.

    Django is now up and running, and I like it so far. I sure is a lot nicer to work with then with JSP and servlets. Enjoy your python

    Comments (4) Trackbacks (0)
    1. Hi Kfir,
      I recently sign up for a dreamhost account and I’m trying to get a django site running on their servers. I followed Jeff Croft guide and my application is almost completely running except for the fact that the admin site doesn’t work quite well.
      I can access the admin site, but when I try to add something, a TemplateDoesNotExist exception is thrown.

      Can you please help me on that?
      I can give you more information if you need it.

      Thanks

    2. Hi Gonzalo
      I am at work at the moment so I can’t help much now, I’ll look into it when I get home. However Dreamhost now officially supports Django. Which means that:
      a. You can install it through the goodies I believe.
      b. The official dreamhost support can now lend a hand.
      I suggest you mail them about it. I’ll also look into it when I get home. Most Django work I do now is for intranet work so it has been a while.

      Edit:

      Ok I spent some time with my django on dreamhost and it seems to be working. Can you tell me which template he fails to find?
      My guess is it is either that there is an error somewhere else and django is getting an auto generated error page request, for which it has no template, or that something is not correctly set in your admin media. Again. If you can tell me what template he fails to find, I can help you more.
      Cheers
      Kfir

    3. Kfir, thanks for the quick responses.
      I think I found the problem, but I don’t know how to solve it.
      The error raises when adding an item that has an ImageField. I think the problem is related with some permission issue.
      I have a symbolic link to the upload path in my document root.

      Do you have any idea of what might be happening?

      Thanks in advance.

    4. Another thing, the exception is raised and the admin site tries to show me a 500 error, and it fails to load 500.html template. So, I have two problems… the image uploading problem and the template not found exception.


    Leave a comment


    Trackbacks are disabled.