Installing Django in Mac OS X Leopard

I’ve been thinking about writing a start-to-finish Django tutorial, creating a simple CMS for a hierarchical web site going from installation of Django on a clean system all the way to a CMS that automatically uploads web pages to a remote web server. It will probably be a while before I get started on that (if I ever do) but I got the opportunity to do a clean Django install yesterday on a new iMac.

Out of the box (as this iMac was) Mac OS X 10.5 (Leopard) has everything you need to start using Django except Django itself. It has Python 2.5, and it has SQLite 3 for storing data. The only thing I installed on the iMac before installing Django was Smultron, because I wanted a nice GUI text editor for editing the configuration files.

There are three steps to setting up Django: installing it, starting a project, and setting up a database to store your web applications.

Install Django on Leopard

  • Log in to your administrative account if you don’t normally work from an administrative account (by default, you do: the first account on Mac OS X is administrative).
  • Download “latest official version” of Django (0.96.1 as I write this). It will be a “tar” file.
  • Click the file once in your downloads stack to unarchive it (Django-0.96.1.tar).
  • Open the terminal (if you don’t have it on your dock, add it to your dock from the Utilities folder in Applications)
  • Type “cd ” (that’s “cd” with a space) in the terminal window.
  • Drag the folder you created from the tar file (Django-0.96.1) from the stack onto the terminal window.
  • Press return in terminal. This moves you into the Django installation folder.
  • Type “sudo python setup.py install”. It will ask for your administrative password when you press return.
  • At this point, Django is mostly installed, but you do need to cover for a broken installation process:

  • In the downloads stack, open the Django-0.96.1 folder, go into django, contrib, and then admin.
  • Open a new Finder Window and go into your hard drive, Library, Python, 2.5, site-packages, django, contrib, and admin.
  • Drag media and templates from the first folder to the second folder.
  • Django is now installed. You can leave your administrative account and go to the account you normally use if it is different from your administrative account.

    Start a project in Django

    A project in Django can contain many web applications.

  • Open your Documents folder.
  • Make a new folder; call it something like “Django Projects”.
  • Open the terminal if it isn’t still open.
  • Type “cd ” (again, “cd” with a trailing space).
  • Drag the folder you just created into the terminal.
  • Press return in the terminal window.
  • Type “django-admin.py startproject CMS”.
  • Look in the Django Projects folder for the newly created CMS folder.
  • You now have a Django project created. You can now tell Django to start a web server, and you can view that web server in Safari.

  • In the same terminal window, type “cd CMS”.
  • Type “python manage.py ... Lire la suite de l'article