Your problem is this. You're prepending SCRIPTNAME to PATHINFO each time so
it adds another /admin for every successive request. What I suggest doing is
adding 3 Location directives in your apache configuration for /admin /foo
and /bar. But if you want it done the way you have set up, create some
middleware that acts on each request to set environ['PATHINFO'] equal to
environ['SOMEVAR'] that you set in the .wsgi script as environ['SOMEVAR'] =
environ['SCRIPTNAME'] + environ['PATHINFO']. This way, you application will
know the exact path regardless of the previous request instead of adding the
previous request.

Ask any questions you have, please, because I wrote this up kinda quick.

On Mon, Oct 27, 2008 at 5:01 PM, Giles Thomas <
[EMAIL PROTECTED]> wrote:

>
> Hi all,
>
> I'm trying to get mod_wsgi working with Django (1.0), and I've hit a
> problem that I can't seem to be able to solve.  It's simple enough that
> I'm sure the solution is obvious and I'm just being stupid, but I've not
> been able to find anything that works, even after several hours
> searching and trying alternatives :-(   Any help for a struggling
> mod_wsgi newbie would be much appreciated!
>
> The situation is: I have a simple app.  It works in Django's test
> server, and is meant to serve from three base URLs - let's call them
> /admin, /foo, and /bar.  My url.py therefore looks something like this:
>
> -----------------------------------------------
> urlpatterns = patterns('',
>    (r'^admin/(.*)', admin.site.root),
>    (r'^foo/', another.handler),
>    (r'^bar/', yet.another.handler)
> )
> -----------------------------------------------
>
> In the dev server, these are available as /admin, /foo, and /bar.
>
> Now, for production, I want Apache to be serving the root (for example,
> the static pages located at /d, /e and /f) but I want /admin, /foo, and
> /bar to go to Django via mod_wsgi.  After some experimentation, and
> after reference to the documentation [1] I hit upon this Apache config:
>
> -----------------------------------------------
>    WSGIScriptAlias /admin /path/to/my/wsgifile/config.wsgi
>    WSGIScriptAlias /foo /path/to/my/wsgifile/config.wsgi
>    WSGIScriptAlias /bar /path/to/my/wsgifile/config.wsgi
>    <Directory /path/to/my/wsgifile/>
>        Order deny,allow
>        Allow from all
>    </Directory>
> -----------------------------------------------
>
> The problem with this is that although access to /admin, /foo and /bar
> was being delegated to Django correctly, the URL that was passed to
> Django had the /admin (or whatever) stripped off - so its URL matching
> did not work.  So, I tried using some code from the documentation to add
> it back in - in config.wsgi, I put (with mysite.settings and the
> sys.path.append changed, of course):
>
> -----------------------------------------------
> import os, sys
> sys.path.append('/usr/local/django')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> import django.core.handlers.wsgi
>
> _application = django.core.handlers.wsgi.WSGIHandler()
>
> def application(environ, start_response):
>    environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
>    return _application(environ, start_response)
> -----------------------------------------------
>
> I was unsure about this, as it looked like it was for versions of Django
> prior to 1.0, and anyway seemed to be a workaround for a now-fixed
> Django bug - but it seemed to work, until I tried to log in using
> Django's admin interface, under /admin.  When I did that, the login page
> appeared correctly, but logging in tried to redirect me to
> /admin/admin/admin.  After looking at a few other examples, my best
> guess is that pages that did redirects were somehow appending an extra
> copy of the SCRIPT_NAME at the start of the URL.
>
> I'm not sure what to make of all this but I guess my modified
> config.wsgi is completely wrong...
>
> Is that correct?  And if so, what is the right way to configure mod_wsgi
> so that it handles these "root-level" URLs but also passes them down to
> the Django URL resolver?
>
> Any help would be much appreciated!
>
>
> Cheers,
>
> Giles
>
>
> [1] http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> --
> Giles Thomas
> MD & CTO, Resolver Systems Ltd.
> [EMAIL PROTECTED]
> +44 (0) 20 7253 6372
>
> Try out Resolver One! <http://www.resolversystems.com/get-it/>
>
> 17a Clerkenwell Road, London EC1M 5RD, UK
> VAT No.: GB 893 5643 79
> Registered in England and Wales as company number 5467329.
> Registered address: 843 Finchley Road, London NW11 8NA, UK
>
>
>
> >
>


-- 
Michael Beaumont

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to modwsgi@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to