[modwsgi] Re: trouble with django and trailing slashes.

2008-09-18 Thread bobince

I'm not using Django, but there's definitely something wacky about
trailing slashes in mod_wsgi (2.3, running on Apache 2.2). It's not a
problem for me, but it's rather curious.

With a WSGI app mounted at /app, a request to /app/x/y/z gives (as
expected):

SCRIPT_NAME: /app
PATH_INFO: /x/y/z

However, asking for /app/x/y/z/ gives:

SCRIPT_NAME: /app/x/y/z/
PATH_INFO: (empty string)

I can't really see why this would be happening - a brief look at the
source seems to say mod_wsgi takes these variables directly from
Apache*, but CGI scripts do not see the same behaviour.

* - well, pretty much. There are the while (*var  (*(var +1) ==
'/')) var++; loops for both script_name and path_info starting on
line 6327, which I don't really understand what they're doing. It
looks like they're assuming the first character of each must be '/',
and then skipping any extra leading slashes - but is that necessary,
when ap_no2slash is being called immediately afterwards? For path_info
I would rather have the unprocessed value anyway really. Either way,
it doesn't explain how the entire URL path is getting into SCRIPT_NAME
in the first place.

--
And Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-18 Thread Graham Dumpleton

2008/9/19 Graham Dumpleton [EMAIL PROTECTED]:
 2008/9/19 bobince [EMAIL PROTECTED]:

 I'm not using Django, but there's definitely something wacky about
 trailing slashes in mod_wsgi (2.3, running on Apache 2.2). It's not a
 problem for me, but it's rather curious.

 With a WSGI app mounted at /app, a request to /app/x/y/z gives (as
 expected):

 SCRIPT_NAME: /app
 PATH_INFO: /x/y/z

 However, asking for /app/x/y/z/ gives:

 SCRIPT_NAME: /app/x/y/z/
 PATH_INFO: (empty string)

 I can't really see why this would be happening - a brief look at the
 source seems to say mod_wsgi takes these variables directly from
 Apache*, but CGI scripts do not see the same behaviour.

 * - well, pretty much. There are the while (*var  (*(var +1) ==
 '/')) var++; loops for both script_name and path_info starting on
 line 6327, which I don't really understand what they're doing. It
 looks like they're assuming the first character of each must be '/',
 and then skipping any extra leading slashes - but is that necessary,
 when ap_no2slash is being called immediately afterwards? For path_info
 I would rather have the unprocessed value anyway really. Either way,
 it doesn't explain how the entire URL path is getting into SCRIPT_NAME
 in the first place.

 Exactly which version of Apache are you using?

 There was also the recent post at:

  
 http://groups.google.com/group/modwsgi/browse_frm/thread/1294f169ad4d36c?hl=en

 where someone else thought documentation was wrong about trailing slashes.

 I am wondering whether some Apache patch revision has changed
 behaviour on me in some way. This wouldn't be the first time where
 some underlying Apache function I used changed how it worked. In some
 cases I had to duplicate the Apache function just so I got consistent
 behaviour between Apache versions.

 As to the code you point out in mod_wsgi.c, I do some fiddles in there
 to make what is passed through consistent between Apache 1.3 and
 Apache 2.X. In Apache 1.3, from memory it didn't collapse repeating
 leading slashes.

 I saw it as being better to normalise them properly because some WSGI
 frameworks I looked at at the time didn't real deal with possibility
 of repeating slashes and would give unpredictable behaviour.

Hmmm, I asked the wrong question. Can I just see what
WSGIScriptAlias/WSGIScriptAliasMatch line you are using? Of if using
AddHandler/SetHandler what you are using and specifically what context
you are using it in, eg. Directory/Location/.htaccess? Finally, if you
have any mod_rewrite rules in configuration files, what are they?

Graham

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Walter Cruz

For the sake of the archives and spiders, it workerd after
FORCE_SCRIPT_NAME='' has been added to settings.py in django.

[]'s
- Walter

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Graham Dumpleton

2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 For the sake of the archives and spiders, it workerd after
 FORCE_SCRIPT_NAME='' has been added to settings.py in django.

What version of Django are you using?

Graham

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Graham Dumpleton

2008/9/18 Graham Dumpleton [EMAIL PROTECTED]:
 2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 For the sake of the archives and spiders, it workerd after
 FORCE_SCRIPT_NAME='' has been added to settings.py in django.

 What version of Django are you using?

And also post what you have in your urls.py file as well.

Almost starting to look like you are using Django 1.0 and are still
using the workaround for pre 1.0 versions to deal with mounting at sub
URL when you shouldn't be.

Graham

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Walter Cruz

On Wed, Sep 17, 2008 at 9:37 PM, Graham Dumpleton
[EMAIL PROTECTED] wrote:

 2008/9/18 Graham Dumpleton [EMAIL PROTECTED]:
 2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 For the sake of the archives and spiders, it workerd after
 FORCE_SCRIPT_NAME='' has been added to settings.py in django.

 What version of Django are you using?

Yes, Django 1.0.

My urls.py :

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
 #(r'^alinemenezes/', include('alinemenezes.unb.views.index')),

# Uncomment this for admin:
 #(r'^index', include('alinemenezes.unb.views.index')),
# (r'^$', 'alinemenezes.unb.views.index'),
 (r'^unb/$', 'alinemenezes.unb.views.index'),
 (r'^unb/admin/(.*)', admin.site.root),
 #(r'^unb/media/(?Ppath.*)$', 'django.views.static.serve',
{'document_root': '/home/digo/python/django_projects/media/'
}),
 (r'^unb/media/(?Ppath.*)$', 'django.views.static.serve',
{'document_root': '/home/walter/django_projects/media/'}),
 (r'^frases/',  include('alinemenezes.frases.urls')),
)

[]'s
- Walter

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Graham Dumpleton

2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 On Wed, Sep 17, 2008 at 9:37 PM, Graham Dumpleton
 [EMAIL PROTECTED] wrote:

 2008/9/18 Graham Dumpleton [EMAIL PROTECTED]:
 2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 For the sake of the archives and spiders, it workerd after
 FORCE_SCRIPT_NAME='' has been added to settings.py in django.

 What version of Django are you using?

 Yes, Django 1.0.

If you are using Django 1.0, you are NOT supposed to be using:

def application(environ, start_response):
   environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
   return _application(environ, start_response)

The mod_wsgi integration is quite specific about this only applying to
older Python versions.

 My urls.py :

 from django.conf.urls.defaults import *
 from django.contrib import admin
 admin.autodiscover()

 urlpatterns = patterns('',
# Example:
 #(r'^alinemenezes/', include('alinemenezes.unb.views.index')),

# Uncomment this for admin:
 #(r'^index', include('alinemenezes.unb.views.index')),
 # (r'^$', 'alinemenezes.unb.views.index'),
 (r'^unb/$', 'alinemenezes.unb.views.index'),
 (r'^unb/admin/(.*)', admin.site.root),
 #(r'^unb/media/(?Ppath.*)$', 'django.views.static.serve',
 {'document_root': '/home/digo/python/django_projects/media/'
 }),
 (r'^unb/media/(?Ppath.*)$', 'django.views.static.serve',
 {'document_root': '/home/walter/django_projects/media/'}),
 (r'^frases/',  include('alinemenezes.frases.urls')),
 )

In Django 1.0, the URL mount point shouldn't appear in the urls.py
rules. You haven't done that, so that at least is correct.

So as per documentation, use application entry point of:

  import django.core.handlers.wsgi
  application = django.core.handlers.wsgi.WSGIHandler()

and see if that works.

Graham

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Walter Cruz

hum.. my prefix is 'unb' :) (I had simplified the case in the first
e-mail). Should I take it off the urls.py?

[]'s
- Walter

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[modwsgi] Re: trouble with django and trailing slashes.

2008-09-17 Thread Graham Dumpleton

2008/9/18 Walter Cruz [EMAIL PROTECTED]:

 hum.. my prefix is 'unb' :) (I had simplified the case in the first
 e-mail). Should I take it off the urls.py?

Let me quote the documentation below. All that below applies only to
pre Django 1.0. So if using Django 1.0 and you have made both the
changes described, you should undo it and just do everything as if it
was mounted at the root of the web server and Django will adjust
everything properly itself for the case that you then actually mount
it at a sub URL.


That mod_wsgi separates WSGI applications in this way should mean it
is possible to run multiple Django applications under the same
VirtualHost at different mount points. Unfortunately, Django's WSGI
adapter prior to alpha versions of version 1.0, do not honour properly
the WSGI SCRIPT_NAME environment variable, instead ignoring it and
expecting the full request URI to be in PATH_INFO.

This issue and the problems it causes has been raised in Django ticket
#285. Related problems that effectively stem from the same issue have
also been raised in Django tickets #2407 and #1516.

A change to Django which addresses this issue is in the works for
version 1.0 and is described in Django ticket #8015. For older
versions, the workaround presented in Django ticket #2407 can be used
with the script file being written as:

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)

With this change however, it will be necessary to ensure that any
paths listed in the Django urls.py file be prefixed with the value of
SCRIPT_NAME minus the leading slash. For example where the mount point
is '/mysite' the URL patterns would need to be listed as:

urlpatterns = patterns('',
 (r'^mysite/admin/', include('django.contrib.admin.urls')),
)

As long as these changes are made however, it would then be possible
to host multiple Django applications at different mount points within
the one VirtualHost.


Graham

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---