|Version 4 (modified by 10 years ago) (diff),|
The aim of this page is to describe getting Django to run on Windows, served by IIS and with an SQL Server backend.
Useful for people who already have such a setup (You wont find me discussing the installation of SQL Server here) and can't justify (or just don't want) Apache and PostgreSQL as well.
Edit: NB, I'm working from Windows Server 2003/IIS 6 and SQL Server 2005. Credit to: http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/ for the Django on Windows with Postgres/Apache guide, from which I have grabbed some parts of the django-on-windows setup.
- Install Python
- Install Python's Windows extensions
- Install an ISAPI extension for IIS
- Install Django
- Configure Django to look at SQL Server
Head to http://www.python.org/ and look at the menu on the left; in the "quick links" section is a link to the Windows installer for the latest stable version of Python. Download and run it, following the wizard steps until it is complete.
Install Win32 extensions for Python
These are some Windows specific extensions for Python, and they are (I think) required for the IIS driver later.
Visit https://sourceforge.net/projects/pywin32/ and download the Windows installer, run through it. ( That URL looks neater, but the download link gives Error 500 at the moment. This one seems to work though: http://sourceforge.net/project/showfiles.php?group_id=78018 )
Install an ISAPI extension for IIS
This is an extension that loads the Python interpreter into memory while IIS is running, and uses it to serve requests more quickly. CGI apps need to start a new instance of the interpreter for every request, this does not have that overhead - it performs a similar service to mod_python on Apache servers.
Go to http://pyisapie.sourceforge.net/ and download it (look in the menu on the right, under "Links" for a download link). Unzip the archive so you can copy files out of it.
Documentation is in the readme files, but at the time of writing the install is:
- Copy the PyISAPIe.dll file to your Python path, e.g. c:\python24
- Set the security permissions on the dll file so that IIS can read it. In the case of IIS/Server 2003 you need to give read permissions to the "Network Service" account
- Look in the <extracted archive>\source\PyISAPIe\Python\ folder and copy the Http folder to c:\python24\lib\site-packages (adjust, depending on where you installed Python)
- Open the IIS Manager from Administrative Tools, and create a new virtual directory in your website (give it permissions to execute ISAPI extensions when the wizard asks.
- Go to the properties of the folder, click on the configuration button (if it's greyed out, click 'create' first), and add a new wildcard extension (the lower box), locate the pyisapie.dll file and untick the "check file exists" box.
- IIS 6 Specific: In the IIS Manager, go to the "Web Service Extensions" section, and right click -> add new web service extension.
- Give it a name, add the pyisapie.dll fill as a required file and check the box to set the extension status to allowed.
That's it installed. In the <extracted archive>\source\PyISAPIe\Python\examples folder is a file called Info.py. Copy this to your new virtual directory folder, and then try and view http:// your site / info.py
It should work. If it doesn't, when you find out why please come back and explain what happened and how you fixed it. ;)
The PyISAPIe extension has a driver for Django as well, so that's where I will be heading next.
Get the development version if you wish
If you want to keep up with the latest Django developments, you will need to download and install a subversion client for Windows. (e.g. Tortoise SVN, install it, then create a new folder somewhere. Right click on it, and choose to SVN Checkout. Give the URL of the repository as: http://code.djangoproject.com/svn/django/trunk/ and click OK.)
Or get the normal version
Otherwise, just download Django from the main site, and extract the archive to a folder.
Install of Django
Drop to a command prompt (start -> run -> cmd -> OK), change to your Python folder and install Django. Example:
c:\> cd python24\django c:\python24\django> python setup.py install
NB: You will probably need to do some messing around with paths and such to make this work neatly. I'm afraid I'm leaving that to you for now. Without doing that you can still test the Django install, but will need a full path to django-admin.py:
E:\> md test e:\> cd test E:\test>d:\Python24\django\django\bin\django-admin.py startproject proj E:\test>cd proj E:\test\proj>python manage.py runserver Validating models... 0 errors found. Django version 0.95 (post-magic-removal), using settings 'proj.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
Now open a web browser, and visit the site. It should serve a neat page to you.
Linking Django to PyISAPI
Next, you must follow the readme in the PyISAPI examples\django folder (it explains where to copy two files). Then edit the isapi.py file you just copied. See where it says you should change a line? If applicable, edit it for your django.settings.module settings.
Serving Django with IIS
You have created a new virtual folder in IIS, and added the PyISAPI extension, and tweaked it to drive django sites. There is also an addition to Django so it can be driven by PyISAPIe. And, you can now use django-admin.py to create a site inside the virtual folder.
You have everything you need to have Django running from IIS.
I'll update this page when I get it working. ;)