Django under IIS (with HeliconZoo) in virtual directory - urls resolver works with path without directory name

StackOverflow https://stackoverflow.com/questions/17837546

Question

I've a Django website running under IIS with a help of Helicon Zoo. It is located in virtual directory (so, url to it looks like http://mysite.com/django).

In my urls.py, I have patterns defined like this:

urlpatterns = patterns('',
    ....        
    url(r'^django/status/(?P<product>.*)/$',views.status),
    .... 
)

But, when I open url like http://mysite.com/django/status/some_product I'm getting 404 page with message:

Using the URLconf defined in urls, Django tried these URL patterns, in this order:
....
The current URL, status/some_product/, didn't match any of these.

As you can see, there is no django in URL which is tested. And of course, when I change pattern like this:

url(r'^status/(?P<product>.*)/$',views.status),

Everything works fine, but if APPEND_SLASH is enabled (and I have it enabled and setting it to False in settings.py does not help for some reason), my requests like http://mysite.com/django/status/some_product are redirected to http://mysite.com/status/some_product/.

So, the question is: How can I configure Django so it will not throw out virtual directory name?

Is there anything I need to know about how to turn of APPEND_SLASH? Right now I simply put APPEND_SLASH = False in settings.py, but no difference.

Note: I know almost nothing about Django and Python and I can't change how that website is set up (at least now).

Was it helpful?

Solution 2

Finally, I've found what's wrong with it.

Appeared that the reason for described behavior is a setting provided with default web.config file:

<add name="django.root" value="%APPL_VIRTUAL_PATH%" />          

After I removed it everything started working fine.

Here is some info related to django.root variable applied to Apache.

OTHER TIPS

I noticed that the zoofcgi has two operating modes

with django_settings_module

or with wsgi_app

As my project needs the second (wsgi_app), I noticed that the problem was not solved only by setting the variable django.root.

That is, there is a bug in the configuration of environmental variables for the second mode. So I created the project helicon-zoofcgi that solves this bug.

Now there is no need to be entering the site prefix in django urls, the zoofcgi module already solves it in the environment variables.

I hope that the project can be useful for someone in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top