This is possibly one of the easier ways to install a Django development environment for your Windows Vista 32-bit machine. (Alternatively, there’s Instant Django, it’s much like Instant Rails where you just extract it out and can start immediately.)

0. Objective

Objective is to create an application with Django. This guide assumes you have no knowledge in Python, Django or Windows Vista. It does, however, assumes you know and already set up MySQL nicely. Just for you information, I use XAMPP Lite for development in PHP. I run XAMPP Lite’s MySQL and administer my MySQL with phpMyAdmin.

Let’s look at the required downloads. We will need 3 things:

  1. Python 2.6: Django requires Python to function, we’ll grab the latest Windows binary here. (Get the one that says something like Python 2.6.2 Windows installer)
  2. Django: You can get Django here. Use option 2 if you don’t know what SVN is about.
  3. MySQL for Python: This lets Python use MySQL, it does not install MySQL. You can get it here. (Download the one that says ‘MySQL-python-1.2.2.win32-py2.5.exe’ inside the ‘mysql-python’ package.

1. Installing Python 2.6

The installer is pretty straightforward. This guide assumes you install in ‘C:Python26’, the default installation directory. (Do not install in your Program Files as Program Files somehow has lesser access rights.) You should not encounter any error.

After completion of the Python 2.6 installation, set up your environment variables. We want to be able to just type ‘django-admin.py startproject mysite’ in the command prompt. In order to do that, you will have to specify the directory that Windows Vista can search for to find ‘django-admin.py’.

We can do so by going to your Control Panel and type ‘environ…’ at the search area. We’ll get the following:

Editing system environment variables in Windows Vista.

Click on ‘Edit the system environment variables’, a dialog box will pop up. Click on ‘Environment Variables…’, you should be greeted with the following dialog box:

Editing the path for environment variables

My path looks like this before I add anything:

%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem

Append these two directories at the back of what is already there:

;C:Python26Scripts;C:Python26

Remember that each directory has to be separated with a semicolon. My Python is installed in ‘C:Python26’.

2. Installing Django

Extract the Django package that you download to ‘C:django’. Use the Command Prompt to navigate to the folder you extract to, in our case, we can type this command:

cd C:django

Then we have to set up Django:

python setup.py install

And we wait for the the installation to complete. On completion, Django is now fully installed. Let’s try to create an application now to see if it’s working. I created a folder at ‘C:projects’ to store all my projects. Once again, we use the Command Prompt to navigate there:

cd C:projects

Then we create our first Django application:

django-admin.py startproject mysite

Note your C:projects, it now has an additional folder called ‘mysite’ with the following files:

mysite/

  __init__.py

  manage.py

  settings.py

  urls.py

Okay, let’s try to see if every thing is working fine.

cd C:projectsmysite

We will start the server now within the ‘mysite’ directory:

python manage.py runserver

The following should appear:

Validating models…

0 errors found.

Django version 0.97-pre-SVN-unknown, using settings ‘mysite.settings’

Development server is running at http://127.0.0.1:8000/

Quit the server with CTRL-BREAK.

Note that the version number is different, depending on what you download. Now go to your browser and type in ‘http://127.0.0.1:8000/'.

Django worked

And it worked! Congratulations on your first Django-powered page.

3. Installing MySQL for Python

Install MySQL for Python as administrator

Once again, I assumed you had MySQL installed already and know how to run and use it.

Run, in administrative mode, the file you just downloaded – MySQL-python-1.2.2.win32-py2.5.exe.

You may run into errors if you do not install as an administrator due to Windows Vista’s security model.

Now, let’s test if the MySQL installation worked. Run the server if it isn’t started. Edit the database setting in ‘mysite/settings.py’.

Update your database information. Save your file. The server will detect a change once you save your file and start to check for errors again. (I personally find this really cool.)

Here’s what I fill in. Your user may not be ‘root’.

DATABASE_ENGINE = ‘mysql’

DATABASE_NAME = “

DATABASE_USER = ‘root’

DATABASE_PASSWORD = “

DATABASE_HOST = “

DATABASE_PORT = “

If you see no error messages, the database is correctly set up. To do a bit of testing, we can set our user name wrongly on purpose and watch Python throw out the errors then correct it.

Fill in your DATABASE_NAME correctly and we can start coding already. You can continue on the Django tutorial here.

[ad#highlight]

[Forgive me if there’re any mistakes in this tutorial and feedback to me.]

comments powered by Disqus