0

I've managed to configure PyISAPIe to run Python code (eg, a simple hello world) from a new website running on IIS7, but I can't quite figure out how to get Django up and running in the same environment.

Anyone with any tips on how to make that finally link between the two?

This is a simple test server so I don't even need to bother with multiple instances. I just want to run one instance of the site at '/'.

Here's my entire isapi.py file:

import os
import sys
from Http.WSGI import RunWSGI
from Http import Env

from django.core.handlers.wsgi import WSGIHandler as DjangoHandler


sys.path = [
    'c:\parlour\site',
    'c:\parlour\site\lib',
    'c:\parlour\site\project'
] + sys.path

os.environ["DJANGO_SETTINGS_MODULE"] = 'project.settings'

Base = '/'
Exclude = ['/media']

def Request():
  PathInfo = Env.PATH_INFO

  if not PathInfo.startswith(Base):
    return True

  for Excl in Exclude:
    if PathInfo.startswith(Excl):
      return True

  return RunWSGI(DjangoHandler(), Base=Base)

I think the biggest disconnect I'm having is understanding how PyISAPIe know to execute the file above. With Apache, you need to include WSGIScriptAlias / /path/to/mysite/apache/project.wsgi. I don't see an equivalent for PyIASPIe, although it's likely I'm overlooking something obvious.

notanumber
  • 127
  • 4

1 Answers1

1

It is impossible to run Django in any fashion that appends .py to the end of your urls.

What is your reasoning for avoiding the built in Django development server? It works quite well in most environments and works right out of the box without further configuration?

PyASPIe isn't a recommended way to get Django running under IIS, but since it does implement a WSGI interface, I'd say that you should start with that. Have you tried the stuff in the example WSGI config file which includes a bit about django?

http://sourceforge.net/apps/trac/pyisapie/browser/Trunk/PyISAPIe/Python/Examples/WSGI/Isapi.py

As a side note, this is probably a bad way to run a dev server, since you will probably have to restart the server every single time you make a change in your python code. This is just one of many reasons to use Django's built in dev server.

Edit:

The configuration does contain pretty much everything you need to get Django running, as far as I can tell. The lines that do the magic are these:

from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"

You just need to make sure that your project and Django itself are in your PYTHONPATH and that you can import your project's settings.

Then you just need to set the PyISAPIe urls to "/" like so:

Apps = {
  "/"  : lambda P: RunWSGI(DjangoHandler()),
}

Then your Django urlconf should work as expected.

Paul McMillan
  • 1,219
  • 1
  • 8
  • 17
  • To clarify, things run fine with the built-in development server, this is just my next step before deploying to a real server. This is part of a research project for my company. We're looking into using IIS for Django seeing as many of our clients request IIS. I have looked at the included examples, they just seem to fall short of explaining how to make the link from Django to IIS. – notanumber Oct 15 '10 at 20:38
  • I've updated the answer a bit. What's the specific problem if you put in the relevant bits of that file? – Paul McMillan Oct 15 '10 at 21:21