Django using PyIASPIe & IIS7

109 views
Skip to first unread message

notanumber

unread,
Oct 18, 2010, 3:11:55 PM10/18/10
to PyISAPIe
Hi All,

Doing a research project to determine feasibility of using Django on
ISS for my employer. Trying to get it up and running, but having some
issues. Most of my experience is with Django on Ubuntu using Apache,
so I'm pretty easily confused by IIS. That said, I'd appreciate any
help.

So far, I can serve `Info.py` without a problem, but can't seem to get
Django to run -- looking at 500 errors.

I have one virtual site with `pysisapie.dll` mapped to "*.py". The
PyISAPIe code is installed in "C:\pyisapie\". The virtual site has
the root folder set to the default: "\inetpub\wwwroot\" and the Django
site code is in a root folder "c:\project\". Due to the way my
company deploys their sites, I have Django installed in a subfolder of
the site called "lib". Essentially, the layout for the site is:

\project\site\lib -- The reusable libs, including django
\project\site\project -- The project specifics code

Because of the above, I've modified "Isapi.py" to update the
`sys.path`. Here's my entire Isapi.py file:

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

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

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

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'm out of ideas on what could be wrong; IIS doesn't seem to be nearly
as helpful logging error messages as Apache, but that could be just
because I don't know where to look.

Any help would be greatly appreciated.

David

Phillip

unread,
Oct 18, 2010, 3:53:12 PM10/18/10
to PyISAPIe
What version of IIS are you using?

You'll want to set up a wildcard handler and then pass everything off
to Django. You're also using the pass-through version (returning True
from Request) which sends requests back to IIS for other extensions to
handle, but you can't do that for a script mapping.

HTH,

Phillip

notanumber

unread,
Oct 18, 2010, 4:35:00 PM10/18/10
to PyISAPIe
This is IIS7. I've updated the handler to be a "wildcard script
manager" and updated the Isapi.py script to:

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

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

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

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

Base = '/'

def Request():
PathInfo = Env.PATH_INFO

return RunWSGI(DjangoHandler(), Base=Base)

This seem to work much better. At least now I'm looking at a stack
trace instead of just a 500!

Now, I need to figure out why it can't load my database backend.
Isapi.py seems to be mangling the Django errors.

I'm getting this:

django.template.TemplateSyntaxError: Caught ImproperlyConfigured while
rendering: 'django.db.backends.postgresql_psycopg2' isn't an available
database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2',
'sqlite3'
Error was: cannot import name utils

Is there some reason it doesn't show the default Django error handler?

Phillip

unread,
Oct 18, 2010, 5:59:13 PM10/18/10
to PyISAPIe
You'd get a non-Django error only if its WSGI handler threw it- maybe
Django isn't set to display errors? I think there's a debug flag to
that effect. It could also be that it's a loading-time error.

As far as the contents of the error go, you might want to make sure
that you can actually access psycopg2 from your current setup- create
your own WSGI application and try importing it. If you don't have
psycopg2 installed, that'd be why for sure ;P

I'm assuming you're seeing the standard PyISAPIe error & stack trace
now? It looks pretty generic with red and blue text, but is still HTML
formatted.

Phillip

notanumber

unread,
Oct 18, 2010, 6:05:45 PM10/18/10
to PyISAPIe
Django has DEBUG=True in the settings.py, so it's set to display
errors. I can confirm that the built-in dev server works as expected
using both sqlite3 and psycopg2.

I am seeing the standard PyISAPIe stack trace, yes.

I'm not sure how I'd go about creating my own wsgi app. I've never
done that before. Wouldn't the ability to use the dev server with
psycopg2 confirm that it's working though?
Reply all
Reply to author
Forward
0 new messages