Django Blog Project #2: Django Webfaction deployment

This is my OLD blog. I've copied this post over to my NEW blog at:

You should be redirected in 2 seconds.

I mentioned in my previous Django post that I'd write about hosting my new Django blog site on Webfaction. As promised, here it is.

I had some problems deploying my first site at Webfaction. First I got an error about pysqlite. I tried using Postgresql, and then I got an error about something else when trying to do a python2.5 syncdb. I think that they didn't set me up with a current Django installation. Luckily the support was prompt and helpful. I ended up reinstalling the Django application from the Webfaction Control Panel. Here are the steps I took to deploy my less than fledgling site.

Sign up for a shared hosting plan at Webfaction

I signed up for Webfaction's lowest plan at $9.50/month with no commitment. Here is their pricing plans.

Play with new account

I got a welcome email within 24 hours with the details about my account. was a domain name which they provided. Visiting this address in my browser showed my the It worked! Django new project page. I also ssh'd into my shell account by using ssh The OS is CentOS5 which, I think, is based on Red Hat. It was a little different than the Ubuntu that I'm used to. I copied some of my configuration files over to make me feel more at home. On my home machine:

$ scp .bashrc
$ scp .screenrc
$ scp .emacs

Reinstall Django

Note, if your Webfaction account is set up properly with Django, you shouldn't need to take these steps. Like I mentioned earlier, I had some problems with my Django installation. So I ended up reinstalling Django. It's not as hard as it sounds-- just a few clicks in the Control Panel.

  1. In my browser, I went to the Webfaction Control Panel at
  2. Under "> Domains / websites", I selected "Applications".
  3. I removed my current Django installation by clicking the icon with the minus sign.
  4. I clicked the icon with the plus sign to add a new application.
  5. I filled in the following information:
    "Name:": django
    "App type:": Django 0.96.2/mod_python 3.3.1/Python 2.5
    Then I clicked the "Create" button.
  6. Finally, I needed to specify which URL path I want to use with my Django application.
    Under "> Domains / websites", I selected "Websites".
  7. I selected the icon with the pencil to edit the website settings.
  8. In the "Site apps:" section, I selected the icon with the plus sign to add a new App and path. I selected "django" as my "App:" and entered "/" (without the quotes) in the "URL path" field. Then I clicked "Update".
  9. After a couple minutes, I was able to view the Django It worked! page at

Upload my project

  1. The welcome message recommends using sftp, but I used rsync instead because I'm more familiar with it:
    sofeng@home:~ $ rsync -avz ~/src/django/myblogsite

  1. I ssh'd into my webfaction shell account:
    sofeng@home:~ $ ssh
  2. I set the PYTHONPATH. (I actually put this in my .bash_profile)
    sofeng@web36:~ $ export PYTHONPATH=$HOME/webapps/django
  3. sofeng@web36:~ $ cd ~/webapps/django/myblogsite
  4. I tried to do a python2.5 syncdb, but got a database error:
    Traceback (most recent call last):
      File "", line 11, in 
      File "/home/sofeng/webapps/django/lib/python2.5/django/core/", line 1672, in execute_manager
        execute_from_command_line(action_mapping, argv)
      File "/home/sofeng/webapps/django/lib/python2.5/django/core/", line 1571, in execute_from_command_line
        action_mapping[action](int(options.verbosity), options.interactive)
      File "/home/sofeng/webapps/django/lib/python2.5/django/core/", line 504, in syncdb
        cursor = connection.cursor()
      File "/home/sofeng/webapps/django/lib/python2.5/django/db/backends/sqlite3/", line 58, in cursor
        self.connection = Database.connect(**kwargs)
    sqlite3.OperationalError: unable to open database file
  5. I needed to edit my file. I changed the following lines:
    DATABASE_NAME = '/home/sofeng/webapps/django/myblogsite/mydatabase.sqlite3'
  6. I tried python2.5 syncdb again:
    $ python2.5 syncdb
    Loading 'initial_data' fixtures...
    No fixtures found.
    It worked.
  7. The next step was to set up the Apache configuration.
    $ cd ~/webapps/django/apache2/conf
  8. I edited the following line in httpd.conf:
        SetEnv DJANGO_SETTINGS_MODULE myblogsite.settings
  9. Then I restarted the Apache server:
    $ ~/webapps/django/apache2/bin/restart
  10. In my browser, I went to, but got an error:
    ImportError at /myview1/
    No module named blog.models
    Request Method:  GET
    Request URL:
    Exception Type:  ImportError
    Exception Value:  No module named blog.models
    Exception Location:  /home/sofeng/webapps/django/lib/python2.5/django/core/ in _get_urlconf_module, line 177
  11. I guess I need my project on the Python path. I edited the following line in httpd.conf:
        PythonPath "['/home/sofeng/webapps/django/myblogsite', '/home/sofeng/webapps/django', '/home/sofeng/webapps/django/lib/python2.5'] + sys.path"
  12. Then I went back to and saw my page. Success!
  13. Note, If you want to see the live site, the real location is: It's not very exciting now, but hopefully I will be able to add some CSS and more blog metadata soon.

Install Mercurial

Update 6/7/2008: By default Webfaction doesn't come with Mercurial installed, but they do allow you to do a user installation. I decided it would be useful to have Mercurial so I could pull and merge changes with greater control. Here are my steps.This will do a user-wide (as opposed to system-wide) installation of Mercurial in ~/bin and ~/lib.

  1. sofeng@home:~/incoming $ wget
  2. sofeng@home:~/incoming $ scp mercurial-1.0.1.tar.gz
  3. sofeng@web36:~ $ mv mercurial-1.0.1.tar.gz ~/tmp
  4. $ cd tmp
  5. $ tar zxvf mercurial-1.0.1.tar.gz
  6. $ cd mercurial-1.0.1
  7. $ make install-home
  8. $ export PYTHONPATH=$HOME/lib/python:$PYTHONPATH
    Note: you will need to put this in your .bashrc instead of your .bash_profile because Mercurial only executes .bashrc on a remote hg push by default.
  9. $ hg version
    Mercurial Distributed SCM (version 1.0.1)
    Copyright (C) 2005-2008 Matt Mackall  and others
    This is free software; see the source for copying conditions. There is NO

Other Errors
  • No module name
    $ python syncdb
    Traceback (most recent call last):
      File "", line 2, in ?
        from import execute_manager
    ImportError: No module named
    You need to set the PYTHONPATH:
    $ export PYTHONPATH=$HOME/webapps/django
    You may get this if you use python syncdb instead of python2.5 syncdb.

Related posts:
   Django Blog Project #1: Creating a basic blog
   Django Blog Project #3: Using CSS and Template Inheritance
   Django Blog Project #4: Adding post metadata
   Django Blog Project #5: YUI CSS and serving static media

No comments:


This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.