Django on Windows
Author: John P. Mulligan
Updated: 29 April 2008 (minor edits)
Back in April 2006, I wrote a HOWTO for installing Django on Windows (link). Since that time, that guide has become quite popular and linked from various places. Unfortunately some of the information in it has become outdated and so it was time to update it.
This page is the new/revised guide that I will be keeping up to date with the latest information. If you have any comments or tips, please post them below.
Enjoy.
Step 0. Read the official documentation
There was a time when the Django documentation, while quite good, was missing quite a bit. But these days it really has just about everything you need. Your first stop should be at the official site to check out the following:
All done? Let’s move on.
Step 1. Install Python
Current version: Python 2.5 (win32)
The first step is to get the latest version of Python installed. Head on over to Python.org and download the latest Windows installer. Double click and run.

For the rest of this guide, the assumption is that you installed Python in C:\Python25\.
Step 2. Install PostreSQL and Psycopg
Current version: PostreSQL 8.2.3 (win32), Psycopg2 2.0.5.1 (win32)
Django supports a few different databases including PostgeSQL, MySQL, and SQLite. Personally, I’m a fan of SQLite for small projects that won’t be getting a huge amount of traffic. PostgreSQL is, however, the “recommended” database for use with Django, so we’ll use that one.
Go the PostgreSQL Downloads page (or FTP Browser) and get the latest Windows version that includes the installer.
Unpack the zip and you’ll have three files (including a README.TXT). Double click the msi file and then walk through the installer. The default options for what gets installed will probably be fine, but take a look through the options and see if there is anything else you want (e.g. PL/Java). Make sure that you have psql and pgAdmin III selected to be installed. You’ll need those:

You will be asked if you want to run Postgres as a service. If you are running Windows 2000 or Windows XP (so it’s an option) I highly recommend you say yes. It will automatically start the database and run it in the background so it’s there when you need it. You’ll need to pick a username and password for the Windows account for the service. It will create the user account for you if it doesn’t already exist.
When configuring your cluster, the default port of 5432/tcp should be fine unless you have a compelling reason to use something else. Select the proper locale (English, United States for me), and encoding (cool kids use UTF-8). You’ll also need to pick your Postgres superuser name and password. Note that this is not the same as the Windows account the service will be running as, and in fact it is not recommended to have the same password for both. I do recommend using postgres as the username, and a nice secure password:

Click through the final screens and finish. You should now have PostgreSQL installed and running as a service. To try it out, go to Start | Programs | PostgreSQL | pgAdmin III and run it. If you have Postgres running properly you should be able to double click on “PostgreSQL Database Server” and see something like the following:

To get Python to talk to the database, you’ll need Psycopg. According to the official Django docs, “version 2 is recommended with postgresql_psycopg2 backend, version 1.1 works also with the postgresql backend.”
The installation is simple, just download the installer built for Windows (i.e. win-psycopg) and run it. But make sure that you grab the right version! Your Psycopg version must be built to match both your Python version and your PostgreSQL version.
Step 3. Install Subversion (SVN)
Current version: Subversion 1.4.3 (win32)
Although you can always install the latest official release of Django, I’ve found that with the amount of active development going on, it’s probably a good idea to grab the latest version from SVN. That’s a lot easier than it sounds, but you will have to install Subversion for Windows to make it happen.
Go to the Subversion Downloads page and download the latest Windows installer with the basic win32 binaries. Once again, the actual installation is simple and consists of clicking through the installer steps.
Also, if you want something a little easier than the command line, you should check out TortoiseSVN. It integrates quite nicely with Windows, and I’ve been quite happy with it so far. You do not, however, need to install it.
Step 4. Install and test Django
Current version: 0.96-pre (svn)
Open a command prompt and change the directory and check out the latest revision from SVN:
C:\> cd C:\Python25\Lib\site-packages
C:\Python25\Lib\site-packages> svn co
http://code.djangoproject.com/svn/django/trunk/django django
It will create a django directory and install a lot of files. Eventually it will finish with something similar to the following:
...
A C:\Python25\lib\site-packages\django\middleware\http.py
A C:\Python25\lib\site-packages\django\middleware\locale.py
A C:\Python25\lib\site-packages\django\middleware\cache.py
A C:\Python25\lib\site-packages\django\middleware\doc.py
U C:\Python25\lib\site-packages\django
Checked out revision 4714.
C:\Python25\Lib\site-packages>
Make a copy of django-admin.py (located in django\bin) and put it in C:\Python25\Scripts. That will make it easier to run in the future. Also, see the note at the end of this guide for tips on setting your Path environment variable.
Congrats, Django is now installed on your system!
By the way, if you ever want to update your Django source to the latest revision, just cd into your django directory and run svn update from there:
C:\Python25\Lib\site-packages>cd django
C:\Python25\Lib\site-packages\django>svn update
U core\management.py
Updated to revision 4716.
At this point, it would probably be a good idea to make sure that your Django install works before you attempt to get it working with Apache and mod_python. So let’s use the tutorial to create a basic Django project and test the setup:
C:\Documents and Settings\John>cd C:\
C:\>cd django
C:\django>django-admin.py startproject testproject
C:\django>cd testproject
C:\django\testproject>python manage.py runserver
Validating models...
0 errors found.
Django version 0.96-pre, using settings 'testproject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[12/Mar/2007 20:45:50] "GET / HTTP/1.1" 404 2063
Assuming you didn’t get any errors, you should be able to open your browser and confirm that it works:

Step 5. Install Apache and mod_python
Current version: Apache 2.2.4, mod_python 3.3.1
Next up is Apache…
While Django does come with an extremely handy development server that you can use for coding and testing apps, you’ll eventually want to be able to push your application into production. So it’s probably a good idea to get a real Apache install up and running that you can play with.
Installing Apache 2.x on Windows wasn’t nearly as difficult as I thought it would be. Basically head on over to the Apache site and grab the latest win32 binaries.
Double click and run the installer. If you get errors saying that the Installation Wizard was interrupted, check out my post about that.
You will need to enter some information about your system. Your network name will generally be your domain (e.g. thinkhole.org). Your server name will probably either be localhost if you only want local access, or your full hostname if you want to be able to access it over the net (e.g. serpent.thinkhole.org). Enter an email address for the administrator and select the option to install for all users on port 80.
Note that if you choose to run Apache on port 8000, it will conflict with the default port for the Django development/test server. Not cool.
Now test to see if Apache is up and running. Point your favorite browser at http://localhost (or 127.0.0.1) and see what happens. If you a see a page similar to the following, you are all set:

A nice feature of Apache on Windows (did I just say that?!) is the Apache Service Monitor that you can access via the icon in the bottom-right of your screen. Just click on it and it will come up. From there you can stop, start, and restart the server:

Quite handy.
Now that Apache is working, it’s time to install mod_python. Download the win32 binaries that match both your Python version and your Apache version. Double click the installer and follow the instructions in the Wizard:

Note that when it asks you for where Apache is installed, in most cases that will be here:
C:\Program Files\Apache Software Foundation\Apache2.2\
After the installer finishes, you still have one more thing to do. Open your Apache configuration file, usually located at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf with notepad. Scroll down and look for a section that includes a bunch of lines that start with LoadModule. Add the following line to that section:
LoadModule python_module modules/mod_python.so
Save the file and close it. Open up the Apache Service Monitor and click Restart. You should see the following text:
The Apache2 service is restarting.
The Apache2 service has restarted.
If you get errors, you probably made a typo in the configuration file when you were editing it. Check it and try again. If you don’t have any errors, you should be all set.
Step 6. Configure Apache for Django
Now that everything is installed and we know that Django is working properly, it’s time to get it working with Apache and mod_python.
Open your Apache2 config file located at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf and add the following to the bottom of the file:
<Location "/testproject/">
SetHandler python-program
PythonPath "['C:/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE testproject.settings
PythonDebug On
</Location>
<Location "/media/">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png)$">
SetHandler None
</LocationMatch>
Make sure you restart Apache after making the changes to httpd.conf.
Assuming there were no errors in any of the steps up to this point, you should now be able to browse to localhost/testproject and be greeted with this page:

If that’s what you see, then you have Django installed and running via Apache and mod_python, ready for anything you can throw at it. Congrats!
Troubleshooting/Notes:
- You might need to adjust your PATH environment variable to make all of this work. To do so, right click My Computer and hit Properties. Go the Advanced tab and click on Environment Variables. Select the Path system variable from the list and click Edit. Make sure that all of the following are included in your path (i.e. Variable value), separated by semicolons:
C:\Python25\Scripts; C:\Python25; C:\Program Files\Subversion\bin;Some people seem to use C:\Python25\tools instead of “scripts”… seems odd to me, but if that’s the case, you’ll need to adjust your path accordingly. That should fix most “command not found” type errors.
Note that if you alter your path while you have a cmd.exe console open, you must restart the console before the changes will take effect.
- According to Phil, having Cygwin installed can potentially screw up your paths. If you are getting ImportErrors, check Colin and Phil’s comments comment below.
- See the comments by Edward Edmonds, Morg, and Nils-Hero below regarding escaping PythonPath in httpd.conf.


March 12th, 2007 at 11:33 pm
Testing. Testing.
Checking to make sure comments work in this page template.
March 13th, 2007 at 12:14 pm
Confused at two point.
1. When I run the command “svn co http://code.djangoproject.com/svn/django/trunk/django django” from step 4, it creates a directory “C:\Python24\Django-0.95.1\django” not “C:\django”. No sweat, just edit the rest of the steps to incorportate that.
2. In the end, we should be able to browse to localhost/testproject? or localhost:8000/testproject? Screenshot says locahost:8000. If I shut down the Django server (running python manage.py runserver) the localhost/testproject doesn’t work which may indicate a mess up in my http:conf pointing to the wrong place (I changed it to point to the django directory I mentioned above).
Just an FYI mostly. Great tutorial! Thanks for it!
March 13th, 2007 at 12:16 pm
Mike:
Regarding your comments…
1. If you run the svn checkout command from the C:\Python25\Lib\site-packages directory as shown in Step 4, it will create a new ‘django’ subdirectory in that one. You’ll end up with the Django framework installed in C:\Python25\Lib\site-packages\django.
In general, when working with SVN and from the console, it is important to pay attention to your current working directory. You might want to check which directory you were in when you ran the svn command.
Also, the C:\django directory is created to store your Django projects. It doesn’t really matter where you put that, and you could call it anything. That’s just what I use.
2. Doh! I linked the wrong screenshot. It’s fixed now, but good catch. :)
Thanks for the comments! I put the revised guide together last night and tried to get most of the glaring mistakes out of it, but I’m sure there are still some areas for improvement. Hopefully everyone will point out tips/corrections along the way.
March 13th, 2007 at 3:57 pm
You created a location “mysite” but you’re browsing to a url at “testproject” I don’t think that will work, unless you created a “testproject” location?
March 13th, 2007 at 7:47 pm
thanks for the update
March 13th, 2007 at 10:23 pm
Justin:
You are correct. That’s a typo, probably due to my attempt to copy some of the examples I used in the “old” guide. It should be fixed now.
Again, thanks for catching the errors. If you find any more, please let me know! :)
Thanks,
John
March 13th, 2007 at 11:59 pm
You might let people know that the
django-admin.py
is in:
C:\Python25\Lib\site-packages\django\bin
Also my SCRIPTS folder was in:
c:\python25\tools\
Also noteworthy is the fact that if you change your PATH in Windows while the command prompt is open you need to close it and open it back up from scratch for it to pull in the new settings (You dont need to reboot on 2000/XP for PATH changes though, although people might know that tip)
March 14th, 2007 at 7:03 am
:( when i’m typing:
C:\django>django-admin.py startproject testproject
It’s not work. It open django-admin.py like a simple text document, but doesn’t start project.
p.s.: Sorry for my bad english. Hello from Russia )
March 14th, 2007 at 7:08 am
Chupa:
Do other Python scripts work for you? It sounds like your Windows file associations might be messed up. Check the action defined for your .py file type.
You can try to run it as: `python django-admin.py startproject testproject` instead.
- John
March 14th, 2007 at 12:41 pm
John:
Thanks! It’s work.
March 14th, 2007 at 4:24 pm
Django Forum:
Both are good points. I’ve updated the page accordingly. :)
- John
March 14th, 2007 at 8:00 pm
Hi John,
Do you have any idea why I’m getting the following error?
“EnvironmentError: Could not import settings ‘testproject.settings’ (Is it on sys.path? Does it have syntax errors?): No module named testproject.settings”
RHH
March 14th, 2007 at 8:10 pm
Changing the “testproject” parent directory to “c:\django” works successfully.
However, changing the “testproject” parent directory to something else, such as “c:\test” produces an EnvironmentError, even after I change the corresponding entry in httpd.conf:
SetHandler python-program
PythonPath “['C:\test'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE testproject.settings
PythonDebug On
March 14th, 2007 at 8:30 pm
RHH:
Does your project still work when using the development server (i.e. manage.py runserver)?
- John
March 22nd, 2007 at 1:08 pm
John - thanks for the tutorial. I am experiencing the same issues RHH is, and to answer your question - yes, the project works when I use the development server. Thanks in advance for your assistance.
-snap-
March 22nd, 2007 at 5:24 pm
Snap/RHH:
I’m not sure if this will help, but are you restarting Apache after making changes to the config? Any time you change anything (Python files and/or Apache config) you need to restart the whole thing when you are using mod_python. You should also make sure you clean out any .pyc files hiding anywhere.
If you do figure out what the problem is, please share the solution so I can update the guide! :)
Thanks,
John
March 25th, 2007 at 11:07 am
Hi,
Got to the point of:
:\django\testproject>python manage.py runserver
and get the following error:
File “manage.py”, line 2, in ?
From django.core.management import execute manager
ImportError: No module named django.core.management
I tried updating django again copying the subversion command shown but it shows I have the latest build. (nb. also the path environment thing didn’t work, so I ended up in the django directory within “site-packages” to run this, but assume that’s the same directory I would have been in had the path update worked).
Otherwise am stuck
Colin
March 27th, 2007 at 7:08 am
Colin
I had this problem, turned out to be Cygwin getting confused between which Python installation to use. I uninstalled Python from Cygwin and added the path to the non-Cygwin install of Phyton to the PATH. Sorted the problem
Phil.
April 25th, 2007 at 3:31 am
Hi,
I wanted to have images in the html pages served by the templates of the django. But, those images are not getting served up by django or the apache server.
Please let me know how to tweak django or apache to serve images also for these html pages
April 27th, 2007 at 11:21 am
A few words about PostgreSQL 8.2 installation on Windows:
If you are just happy to install PostgreSQL in default location (e.g. C:\Program Files\PostgreSQL) with the core and data, then you can skip this.
Otherwise, you might want to install it in another partition, for disk space capacity, etc. (Yes, I know you can create a new tablespace in a different location and assign new databases to it later — but in case that you don’t want to deal with the fuss when you forget to do that once in a while and the database eats up all the space on C: drive, please follow me.) Unfortunately, the PostgreSQL 8.2 installer has a bug, which actually prevents you from installing it in ANY partition other than the system drive (usually, C:). If doubt, have a try. The installer is simply interrupted before reaching the end. Here’s the workaround.
Assumed that the system drive is C: and you want to install PostgreSQL in D:\PostgreSQL .
1. Double click postgresql-8.2.msi, and click next, next…, until Installation Options comes up.
2. Select the root node (PostgreSQL) from the tree, and click Browse. Change the path to D:\PostgreSQL\8.2 .
3. Select Data directory (under Database Server), and click Browse. Change the path to C:\PostgreSQL\8.2\data . Yes, here’s the point: the data directory has to be in the system drive, for getting the installer work. Don’t worry, we’ll change it back later.
4. Follow John’s instrustion and do the rest of the installation process. It should be fine now.
5. After that, from Start menu - Run… , input the following command and press Enter:
services.msc
6. Stop PostgreSQL Database Server 8.2 service from the Service mmc.
7. Enter the command from Start menu -> Run… :
regedit
8. Look for the the following item from the Registry Editor:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pgsql-8.2
Change the value of ImagePath to:
D:\PostgreSQL\8.2\bin\pg_ctl.exe runservice -N “pgsql-8.2″ -D “D:\PostgreSQL\8.2\data\”
9. Open My Computer and browse to C:\ . Select C:\ProgresSQL directory and press Ctrl+C.
10. Browse to D:\ and press Ctrl+V. When it prompts to overwrite files, click All.
11. Start PostgreSQL Database Server 8.2 service from the Service mmc. It should work now. Any newly created databases will be place in D:\PostgreSQL\8.2\data .
12. For perfectionists, there are two more things to do, although I haven’t find any side effects ignoring them:
(1) Delete C:\PostgreSQL directory.
(2) Registry items to be changed:
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{1F…0}
“Data Directory” = “D:\PostgreSQL\8.2\data\”
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Services\pgsql-8.2
“Data Directory” = “D:\PostgreSQL\8.2\data\”
April 28th, 2007 at 10:32 pm
I’m not getting images in my /media/ file on my windows machine running mod_python apache2.2.
If I shove a .css file in there my localhost finds it no problem so I suspect that there is something wrong with the httpd.conf file.
Any ideas?
April 28th, 2007 at 10:36 pm
Ok I figured it out:
I changed this:
To this:
The backslash becomes a forwards slash.
May 12th, 2007 at 7:03 pm
Works with the test server not with apache, however python works fine
My error
EnvironmentError: Could not import settings ‘mysite.settings’ (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings
This is weird I don’t understand why it does not work.
my paths
E:\WORKING_FILES\coa\PythonApps\mycode\mysite\mysite
my config
SetHandler python-program
PythonPath “['C:\Python25'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
SetHandler None
SetHandler None
May 12th, 2007 at 7:17 pm
Ok I have fixed it, its all to do with python paths in apache.
##
SetHandler python-program
PythonPath “['E:\\\\WORKING_FILES\\\\coa\\\\PythonApps\\\\mycode\\\\mysite'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
SetHandler None
SetHandler None
##
May 28th, 2007 at 2:45 am
Hi John,
Thank you for a very detailed tutorial. Since I’m on Windows Vista, I did run into a few issues while installing and running Apache (2.2.4), which I’d like to share here.
1. Apache couldn’t start up after successful installation:
- The configuration files will be installed in the wrong directory if UAC is running. Therefore, UAC must be turned off when you install Apache on Vista.
- To turn off UAC, go to Start -> Run -> type in ‘msconfig’.
- Click on “Tools” tab.
- Select “Disable UAC.”
- Click “Launch” and wait for the CMD window to finish executing the command. Close CMD after it’s done.
- Select “OK” and restart.
2. Apache Monitor couldn’t start up correctly:
- Go to Start Menu -> All Programs -> Apache -> Control Apache Server
- Right click on “Monitor Apache Servers”
- Select “Properties”
- Select “Compatibility” tab
- Check “Run in Compatibility Mode for Windows XP (Service Pack 2)”
- Click “OK”
June 19th, 2007 at 9:01 pm
wow…cool.
It worked..thanks John.
June 29th, 2007 at 4:45 pm
Hi John
Thanks for this. If I want to talk from Django on Windows to a remote Postgres server, is there a simple procedure for modifying this recipe to do that?
Thanks, Jim
June 30th, 2007 at 8:38 pm
I had a small issue with the final settings in the httpd.conf that i would like to share:
1. Having this line: <Location “/testproject”> (note the final slash) and going to localhost/testproject (no final slash) shows 404. Going to localhost/testproject/ works.
2. Changing to: <Location “/testproject”> works for both localhost/testproject and localhost/testproject/
July 7th, 2007 at 3:22 pm
Thanks for the very well explained tutorial, John.
I’ve experienced the same issues that Amenthes above. It was fixed by following his tip.
July 10th, 2007 at 1:59 pm
hi jhon
my name is amaury thanks for the tutorial. its well explained. Im using django and python to build a data base. I have a problem when i going to prube the “templates” i am testing the example on django book chapter 4. This is the code:
>>> from django.template import Template
>>> t = Template(”My name is {{ my_name }}.”)
>>> print t
when i type the second line appears the following error
Traceback (most recent call last):
File “”, line 1, in
t = Template(raw_template)
File “c:\python25\lib\site-packages\django\template\__init__.py”, line 167, in __init__
if settings.TEMPLATE_DEBUG and origin == None:
File “c:\python25\lib\site-packages\django\conf\__init__.py”, line 28, in __getattr__
self._import_settings()
File “c:\python25\lib\site-packages\django\conf\__init__.py”, line 53, in _import_settings
raise EnvironmentError, “Environment variable %s is undefined.” % ENVIRONMENT_VARIABLE
EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined.
I dont know what happend. Im crazy man Im working in a project with this tool. I really appreciated your help. Thank you
July 11th, 2007 at 9:58 am
Just by the way Adrian Holovaty and Jacob Kaplan-Moss, creators of the Django system, have set up a Django Book online at http://www.djangobook.com which is set to be released in 2007. This link should be available at Step 0. Read the official documentation. Enjoy!
July 11th, 2007 at 12:58 pm
Thanks for this tutorial! It helped me alot and i’m new to python and Django. A little modification to this tutorial especially the paths in apache as part of the default tutorial. Otherwise the installation was a success. One more question how would you make a Django project have it’s own name-based virtual host?
July 17th, 2007 at 1:02 pm
I have created a simple, portable django development environment for windows:
http://www.instantdjango.com
No installation required, and it can be run from a usb drive.
My website is not complete yet, but the portable environment is working fine for tutorials.
I created this for people who want to mess around with Django without the hassle of installation, or for people who work at computers where installation is not an option (like me).
Anyway, give it a shot and let me know what you think.
-cjlesh
July 17th, 2007 at 11:29 pm
Thanks for the tutorial!!!
It really helped me out on the installation!
And thanks Amenthes too!
Your info solved my problem with the slashes!
July 27th, 2007 at 3:11 pm
Excellent instruction. I was able setup django, Apache in no time. Keep up the good work.
Thanks a lot,
ash
July 28th, 2007 at 1:36 am
On Windows, you need to escape each backslash twice:
PythonPath “['c:\\\\path\\\\to\\\\project'] + sys.path”
July 29th, 2007 at 5:35 am
———————————–
# RHH Says:
March 14th, 2007 at 8:00 pm
Hi John,
Do you have any idea why I’m getting the following error?
“EnvironmentError: Could not import settings ‘testproject.settings’ (Is it on sys.path? Does it have syntax errors?): No module named testproject.settings”
RHH
———-
=============
me too
?+asڶ2add “C:\django” to your system PATH environment
it work. :)
August 2nd, 2007 at 9:25 am
Hey John, Thanks for the great tutorial, followed it each step and it worked beautifully!
I have a question, being that i’m new to this sort of development, coming from a php world, for the apache lines that were added into the httpd.conf file:
SetHandler python-program PythonPath “['C:\django'] + sys.path” PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE testproject.settings PythonDebug On
do i need to add a new set of that each time i create a new project? so for a new one would it be the following?:
SetHandler python-program PythonPath “['C:\django'] + sys.path” PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE testproject02.settings PythonDebug On
Thanks!
August 13th, 2007 at 12:20 pm
Leaving a comment to say how wonderfully useful this page has been to me. THANKS!
*Thumbs up*
August 20th, 2007 at 5:01 am
Thanks alot. You just don’t know how helpful this page was….
September 18th, 2007 at 5:05 pm
*** Solved problems with HTTPD.CONF ***
I generated Django project under c:\projects\tests and named it ‘django1′, so the following directory got created: ‘c:\projects\tests\django1′.
I had a problems with browsing to http://localhost/django1, but NOT to:
http://localhost/django1/ (note backslash). So final solution was this (notice missing backslash at the end of first line):
SetHandler python-program
PythonPath “[r'C:\\projects\\tests'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE django1.settings
PythonDebug On
SetHandler None
SetHandler None
October 16th, 2007 at 3:51 pm
Thanks so much for the step by step tutorial. This made the process considerably easier that would have been otherwise.
Thanks,
Melissa
November 6th, 2007 at 8:33 am
I’m a newbie to Python. I’ve been having this problem with the ImportError when trying to run the command “python manage.py runserver”.
I did see Colin pointing out the fact that its the Cygwin version of Python thats causing this problem. How do I differentiate between the Cygwin version and the non-Cygwin version of Python? Any pointers will be great. Thanks much!
Karthik
November 29th, 2007 at 8:18 am
Is there any way to serve up the admin pages under apache ? I can do this by running the manage.py runserver, but not via apache.
All the websites I googled tell you to make a symbolic link to the media for admin, but this is windows we are talking about, so what about the admin program itself ?
December 4th, 2007 at 10:37 am
The current mod_python Windows installer looks for python 2.3 during the install process. For other versions of Python/ Apache, try http://www.lehuen.com/nicolas/download/mod_python/
December 13th, 2007 at 9:09 pm
Got a problem on precisely each step of the tutorial… Is that what programming is all about? Will there ever be some fun part too?
December 19th, 2007 at 2:11 pm
@Alex:
Use Junction to create a pseudo-symlink in Windows: http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx
Works a treat.
@John:
Thanks for this excellent tutorial. One thing - please note dig’s comment above about escaping backslashes and amend your code.
Your example works, but if you put your projects elsewhere then mod_python starts throwing the dreaded “EnvironmentError: Could not import settings” error. I found that without escaping, mod_python would find projects only if their directories began with certain letters - truly mystifying to debug.
January 1st, 2008 at 1:10 pm
Your tutorial worked great (minus a few quirks with Vista on my part), thank you for your time that you have put into this. I was pulling my hair out of my head for about two days trying to figure the APache mod_python installation :)
A comment about the issues with slashes. The Django website explains this with good clarity (hopefully you find this worthy of using it to update your website ;)):
“Note
If you’re using Windows, we still recommended that you use forward slashes in the pathnames, even though Windows normally uses the backslash character as its native separator. Apache knows how to convert from the forward slash format to the native format, so this approach is portable and easier to read. (It avoids tricky problems with having to double-escape backslashes.)
This is valid even on a Windows system:
PythonPath “['c:/path/to/project'] + sys.path”
LINK: http://www.djangoproject.com/documentation/modpython/
Also a comment on the Location tag; leave out the trailing slash after “/testproject” so it “should” resemble this:
SetHandler python-program
PythonPath “['C:/django'] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE testproject.settings
PythonDebug On
SetHandler None
SetHandler None
Platform this works on: Windows Vista x86, Python 2.5.1, Apache 2.2.6, mod_python 3.3.1, psycopg2-2.0.6, and Postgresql-8.3-beta4 (so far no issues with psycopg2.0.6 *cross fingures until support for 8.3*).
January 1st, 2008 at 1:13 pm
I guess the Location tags were stripped from my comment ;P Pleas advise my post was supposed to have”
January 14th, 2008 at 8:39 am
Thank you very much! Great article! Everything works fine!
Best Regards,
Jegor.
January 28th, 2008 at 9:27 am
just finished installing mod_python 3.3.1 for like the hundredth time and still haven’t been able to pinpoint why httpd.conf will not restart. Checked that there are no typos. Even copied the file name/location from that published on the install screen from mod_python with no results at all. httpd.conf only restarts when I comment out mdo_python’s LoadModule directive. Help!.Please what else can I do to troubleshoot?
I am using windows XP SP2, Apache 2.2.8 and python 2.5.1.
Thanks in advance
January 28th, 2008 at 2:55 pm
Was having some problems with http.conf after sifting through Django Docs I came up with this solution:
Most of this is the same as the examples above except for the first part in which I changed Location to “/” this way any project started on a development server under c:/your_projects will be served.
Also in testproject.settings.py you have to set all the appropriate paths for the media directories, for me I just copied all the admin media to a folder under htdocs named media and also created a media folder under c:/your_projects/testprojects/ so c:/your_projects/testproject/media and edited settings.py like so:
Also I created a template directory c:/django_projects/testprojects/templates and edit settings.py like so:
After doing this I installed django.contrib.admin and edited urls.py then python manage.py syncdb, everything worked perfectly with no errors.
Maybe this will help some of you.
Cheers,
Edward
January 30th, 2008 at 2:25 am
Hi,
Nice work…… :)
February 13th, 2008 at 10:53 am
This worked for me eventually, but at first I had the same problem bringing up mod_python that obyno reported above. Through research I found out that if mod_python cannot properly bring up the Python environment, the error message you get from Apache is that mod_python cannot be found. There were two reasons why my Python environment worked fine for me, but not for Apache.
The first was I had some of the necessary environment variables set as “User variables” for my account rather than “System variables”. This meant that when Apache ran as a service, it did not get those environment variables.
The second thing that I think was a problem was that I had multiple versions of Python, one for Cygwin and one for native Windows. I got things working by uninstalling all of my Python software and reinstalling only what I needed. It was only after I did the reinstall that I realized that I might have been able to fix things by cleaning out my execution path variable.
February 20th, 2008 at 3:03 am
@Greg: Any chance you can clarify what you mean by “It was only after I did the reinstall that I realized that I might have been able to fix things by cleaning out my execution path variable.”? Am having the same issue as obyno and would love to know the short fix. TIA
March 3rd, 2008 at 9:11 am
I like how many different ways you have found to spell ‘postgreSQL’ =)
March 3rd, 2008 at 2:05 pm
Thanks, for this very nice and helpful tutorial. Really helped me out starting learning hands on django (on a windows development PC). Up to chapter 3 ;-)
March 18th, 2008 at 4:59 pm
I have a problem with “django-admin.py startproject test” … if I execute it, popup Open With pops up (the one where you choose the program you want to use to open this file), …. superweird.
Anyone has a clue what’s wrong?!
March 26th, 2008 at 11:37 pm
Very helpful tutorial, thank you much. Wouldn’t have made it through without you.
March 31st, 2008 at 10:28 am
Thank you very much. It works like a charm. You are the king of django installation tutorials !
April 6th, 2008 at 6:36 pm
“python manage.py runserver” might also produce an ImportError if you (unknowingly) have a separate instance of python installed on your machine.
Try running python at the command line, then within the python shell type:
import sys
sys.prefix
sys.prefix should be C:\Python25. If it’s not you’ll need to adjust your Windows path variable so that the new installation of python appears *before* any other ones.
Most IBM computers ship with a version of Python that is used in some of the “Access IBM” utilities. So if you have a Thinkpad, you might run into this.
April 11th, 2008 at 10:54 am
Hi,
I’ve been trying hard to execute this
svn co http://code.djangoproject.com/svn/django/trunk/django django, but it didn’t work, because of my proxy server.
So, I installed “TortoiseSVN” (because it lets you setup a proxy server).
Then, from TortoiseSVN, I tried again, and the process started! But after a few seconds, I received this error:
”
REPORT request failed on ’snv/!snv/vcc/default’
REPORT of ’snv/!svn/vcc/default’: 400 Bad Request (http://code.djangoproject.com)
”
Could anyone help me?!? I would be very pleased, because it’s been a long time trying to put django to work, and I can’t do it.
Thanks!!
ps: I’m from Argentina, so there could be some errors in my writing.
April 29th, 2008 at 1:02 am
John, thanks for the tut. Please fix (under 6) the line …
PythonPath “['C:\django'] + sys.path”.
… like Morg and Edward Edmonds already mentioned.
r’C:\django’ works,
‘C:\\django’ works,
‘C:/django’ works or
os.path.normcase(’C:/django’) works,
(etc..)
see e.g. here: http://www.codecodex.com/wiki/index.php?title=Escape_sequences#Python
or here: http://www.ferg.org/projects/python_gotchas.html
Nils
May 2nd, 2008 at 5:44 am
halo i wanna ask, after following this step :
Step 6. Configure Apache for Django
Now that everything is installed and we know that Django is working properly, it’s time to get it working with Apache and mod_python.
Open your Apache2 config file located at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf and add the following to the bottom of the file:
SetHandler python-program PythonPath “['C:/django'] + sys.path” PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE testproject.settings PythonDebug On SetHandler None SetHandler None
when i enter in ff localhost/testproject/
it came out error like this :
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, boby@unetco.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
can anyone help? i have tried changing names and path and after i restart it shows up always this error help pls
thx in advance
May 4th, 2008 at 2:14 pm
Guide is amazing. But needs some updates for Postgre installation images. I installed postgresql-8.3.1-1 and install process looks a little bit different.
Anyway, thank you for this guide.
May 7th, 2008 at 10:40 am
@Matt:
You mention using ‘junction’ to replicate the symlink solutions in Windows XP. Can you provide more details on how to do this and the subsequent changes needed to http.conf and settings.py, assuming all of the file paths are per this tutorial?
Thx +1M