Installing Django on OS X

Last updated on 2005-11-13

Several notes before we start: if you just want to play around with Django, you can skip this whole document. Django comes with its own web server for development purposes. The best thing you can do in this scenario is check out the official documentation and follow these instructions.

If you’d like to install Django and try deploying it locally on the standard OS X Apache you can use it with the FastCGI handler.

The guide below is for trying out Django with the mod_python handler.

This is a rough guide to get Django working on a Mac OS X (10.4.3 as I write) machine with Apache 2 and mod_python 3.1.4. It involves lots of fiddling with the command line and it assumes you know what you are doing.

Be sure to have installed a recent build of Django. I recommend using the development version, by checking out the head revision of the Subversion trunk: svn co


This is the stuff I had already installed on my machine before starting (your mileage may vary):

I then had to install Apache 2 and mod_python 3.1.4. I tried using the default Apache 1.3 install which comes with Tiger, together with mod_python 2.7 which I already had installed, but they didn’t work with Django. So:

  1. Download and install Apache 2.0.54 (thanks, Scott Sanders)

    1. cd ~/Desktop
    2. wget
    3. gunzip httpd-2.0.54.tar.gz
    4. tar xvf httpd-2.0.54.tar
    5. cd httpd-2.0.54
    6. ./configure –-enable-so –-with-mpm=worker
    7. make
    8. sudo make install

    This will install Apache 2 in /usr/local/apache2

  2. Download and install mod_python 3.1.4

    1. cd ~/Desktop
    2. wget
    3. gunzip mod_python-3.1.4.tgz
    4. tar xvf mod_python-3.1.4.tar
    5. cd mod_python-3.1.4
    6. ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/bin/python
    7. make
    8. sudo make install

    Then activate it, by editing /usr/local/apache2/conf/httpd.conf and writing in it the following line: LoadModule python_module modules/

Setup the django project

Now that you have Apache 2 and mod_python, you can move on to Django. Follow along the first and second tutorial and create the project myproject inside the ~/Sites directory.

Run django with Apache and mod_python

  1. edit the /etc/hosts file and add a line like this one: django.loc
  2. edit the /usr/local/apache2/conf/httpd.conf file and add the following at the end of it (remember to edit [YOUR USER NAME]):
    <VirtualHost django.loc>
        DocumentRoot /Users/[YOUR USER NAME]/Sites
        <Location /admin/>
            SetHandler mod_python
            PythonHandler django.core.handlers.modpython
            PythonPath sys.path+['/Users/[YOUR USER NAME]/Sites']
            SetEnv DJANGO_SETTINGS_MODULE myproject.settings.admin
  3. If you have the default OS X Apache 1.3 running, stop it with sudo /usr/sbin/apachectl stop
  4. Start Apache 2: sudo /usr/local/apache2/bin/apachectl start
  5. Point your browser to django.loc/admin/ and you should see the following screen:

    django administration login screen

That should be pretty much it: now you can go on and create the users for the admin section, as detailed towards the end of the second django tutorial.

If it worked for you, share and enjoy. If it didn’t, well, I’m sorry I haven’t been of any help. The best thing you can do is log on to the #django IRC channel on and ask for help.

Antonio Cavedoni,