Nov 24, 2013

Getting started with Python and Django

python, django

Python is a dynamically typed scripting language. Django is a web framework built in Python. The two seem like a good match for light, rapid web development. I know neither and this is my experience learning the language and one of the popular frameworks built on top of it. Most likely it will be a distilled version of the various tutorials and getting started guides you may already find on the internets.

I’ve just changed my development machine to a Macbook Pro so keep in ming the following is all written and tested on Mac OS, and I am in the process of learning that as well.

##Installing Python

Mac OS comes with Python already installed. The latest version installed is 2.7. The latest version of Python as of writing is 3.3. There seem to be a significant number of changes from 2.x to 3.x so I decided to go with 3.3. The differences are covered in more detail here. Some popular libraries are not yet compatible with 3.x so keep this in mind when deciding which version of python to target.

##Get virtualenv and pip

Another detail to consider here is running several versions of Python side by side. You will most likely want to have isolated Python environments in case you are working on several projects at the same time, or you just want to future proof your setup a little right off the bat. This can be accomplished using virtualenv. Python3 includes a virtual environment tool but I’m not sure how well that would work with previous versions of Python. Virtualenv seems to be a widely accepted solution to this problem so I decided to stick with that for now.

The best way to get virtualenv is using pip – a tool for installing and managing python packages. You will also need this to grab the latest version of Django the easy way. Follow the instructions here to install pip. Alternatively you can use the command line sudo easy_install pip but there are some documented downsides to this.

##Installing Django

Now that your basic Python environment is set up you can start the fun stuff. Download and install Django using pip: pip install django; Now you’re all set, you can simply follow the tutorials at djangoproject.org to get started with Django.