3

I'm trying to run a site with Django on an IIS-based server. I followed all the instructions on the main site (http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer), and double checked it with a very good article (http://www.messwithsilverlight.com/2009/11/django-on-windows-server-2003-and-iis6/).

I successfully got as far as setting up IIS to read .py files. Following the main instructions, I can get the server to render Info.py. However, I can't seem to get IIS and Django to play nice. If, for instance, my Virtual directory is "abc", then if I go to "localhost/abc/", the browser simply shows me the content directory for that folder. Furthermore, if I have my urls set up so that "/dashboard/1" should bring me to a certain page, entering "localhost/abc/dashboard/1" gives me a "page cannot be displayed" error.

I'm fairly certain IIS simply isn't referencing or interacting with Django at all. Does anyone have any ideas how to fix this?

Thanks

  • any updates, did you find a patch for it? I'm running across the same problem! – Speccy Jan 09 '13 at 01:56
  • @Speccy I also have the same prob, if you find anything worthy please post it! – marlen Jan 10 '13 at 10:37
  • @marlen, I finally managed to get it to work, which version of PyISAPIe are you using? Which version of python? Which version of IIS? – Speccy Jan 10 '13 at 14:46
  • @Speccy cool! PyISAPIe-1.1.0-rc4-Py2.6, python 2.6, IIS6, django 1.4. I think that the problem is something with the PyISAPIe, maybe when linking it with django. What did you do and it worked? – marlen Jan 11 '13 at 08:03
  • @marlen I'm using exactly the same versions, Windows server 2003 I suppose? I will post my answer below :) – Speccy Jan 11 '13 at 12:47
  • @Alex Kaiser Please take a look at my answer. – Speccy Jan 21 '13 at 18:40

2 Answers2

2

Here are the original instructions I followed,

basics instructions: https://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer additional tips: http://whelkaholism.blogspot.ca/

  1. The first thing you should do is install Python 2.5 or 2.6, for 2.7 you need to recompile PyISAPIe, which I have not done. http://www.python.org/ftp/python/2.6/python-2.6.msi
  2. You need to install the version of PyISAPIe that will match your Python Interpreter version, if they do not match, it will fail. Get it there : http://sourceforge.net/projects/pyisapie/files/pyisapie/
  3. Move the extracted folder from the last step at a decent location (i.e. C:)
  4. You need to change the security settings of the PyISAPIe.dll, they suggest Network Service read, but I set everyone, to be sure there are no problems with this
  5. You then have to CUT AND PASTE (Important) the Http folder of PyISAPIe to Lib\Site-Packages of your Python installation directory
  6. Next, you setup IIS (open the manager with inetmgr in run (winkey+r):
    • Add a new virtual directory and allow executing ISAPI extensions when prompted by the wizard
    • Add a new wildcard extension in the property of your virtual directory, untick file exist setting
    • Add Web Service Extension to IIS Manager pointing to the dll, ensure it is allowed
  7. From the PyISAPIe folder, copy examples\django\Isapi.py and paste it in Lib\Site-Packages\Http
  8. In Isapi.py, set the path (i.e. c:\inetpub\wwwroot\ web_site\ django_project ) and DJANGO_SETTINGS_MODULE (i.e. django_app .settings)
  9. When any change is done to your files, use iisreset in your command prompt to apply the changes

Here are some other things you might do

  • Ensure the path of your db file (if sqlite used) is okay
  • Do the same with template location settings
  • In your urls and html files, ensure the path start with the name you gave to your virtual directory alias (i.e. web_site in our example)

Finally, you may encounter difficulties with serving your CSS. If you have any troubles, tell me and I will update my post.

Speccy
  • 694
  • 8
  • 30
  • PS : I'm French Canadian, so tell me for my English errors. I hope to get my first answer accepted =D – Speccy Jan 11 '13 at 13:20
  • @Speecy it still doesn't work for me. Don't u move the pyisapie.py to the handlers folder? My url:'(r'^login/$', 'auth.views.login_user')' and project path: 'D/wwwroot/VPMS/vpms' where vpms is the project and auth is an app. Is 127.0.0.1:8080/login the proper way to call it? – marlen Jan 14 '13 at 11:26
  • @marlen could you test if it is working be creating a new project (manage.py startproject) and from there it would be easy to see if django is running properly. From there, I can help you with setting your particular project. – Speccy Jan 14 '13 at 15:28
  • @speecy I created a new proj as in the tutorial and Hello world showed up on 127.0.0.1:8080/proj/helloworld.py (your instructions worked but I also needed to set DJANGO_SETTINGS_MODULE globally).Shouldn't work just on 127.0.0.1:8080/proj?When I try this I just get the directory.. In my project the url is:'(r'^login/$', 'vpms.views.login_user') where vpms is the django project that's inside c:\wvpms. What's the proper way to see if this one works? – marlen Jan 15 '13 at 14:11
  • @marlen Have you tried (r'^$', 'vpms.views.login_user') as your url? (if you want 127.0.0.1:8080/proj/ working) – Speccy Jan 15 '13 at 18:42
  • @Speechy finally I got it working :D(I was only adding application extension and negleting to insert wildcard application maps -.-)Serving the css is kinda tricky, I also had prob but I managed to serve them. Merci for your help speechy! – marlen Jan 16 '13 at 13:35
  • @marlen haha, you are destroying my nickname. Glad you got it working! I hope my instructions will help other people too. – Speccy Jan 16 '13 at 15:46
0

Serving Django with any webserver basically involves three key details:

  1. Telling the webserver, "I want you to serve content that is provided by this module that invokes python"
  2. Telling the python module, "I want you to execute python code using the details in this file"
  3. Telling the file, "I want you to use Django"

If you're getting a directory listing back for your Virtual Directory then it would seem that you should investigate the VD settings to make sure PyISAPIe is configured for that directory (key details #1).

From the article you mentioned:

  • Open the IIS Management Console, and create a new virtual directory, and allow executing ISAPI extensions when prompted by the wizard.

    • View the properties of the new folder and click on the "configuration" button (if it's greyed out, click 'create' first), then add a new wildcard extension (the lower box), locate the pyisapie.dll file and untick the "check that file exists" box.

    • In the IIS Manager, go to the "Web Service Extensions" section, and right click -> add new web service extension.

  • Give it a name (it doesn't matter what), add the pyisapie.dll fill as a required file and check the box to set the extension status to allowed.

T. Stone
  • 19,209
  • 15
  • 69
  • 97