cannot get REQUEST_URI

287 views
Skip to first unread message

omat * gezgin.com

unread,
Apr 28, 2007, 6:53:55 AM4/28/07
to Django users
I need to use the current request URI in a template. Thus, I am
passing the uri as a context variable, which is:

uri = request.META.get('REQUEST_URI') or request.META.get('PATH_INFO')

When I use this expression in the test server, which uses the
request.META.get('PATH_INFO'), everything is fine but at production
server (apache, mod_python) the value of
request.META.get('REQUEST_URI') is always '/' for any url like 'http://
domain.com/something/'

Thanks for any help...

Sam

unread,
Apr 28, 2007, 10:28:44 AM4/28/07
to Django users
Why don't you also use request.META['PATH_INFO'] at production level ?

uri = request.META.get('PATH_INFO')

omat * gezgin.com

unread,
Apr 28, 2007, 11:22:09 AM4/28/07
to Django users
Because request.META['PATH_INFO'] is only available when running the
test server.

This is also a point of inconvenience and I think the test server
should be made more compatible with apache.

Malcolm Tredinnick

unread,
Apr 28, 2007, 11:42:20 AM4/28/07
to django...@googlegroups.com
On Sat, 2007-04-28 at 15:22 +0000, omat * gezgin.com wrote:
> Because request.META['PATH_INFO'] is only available when running the
> test server.
>
> This is also a point of inconvenience and I think the test server
> should be made more compatible with apache.

Apache is not the only web server in the world, so it is a good thing
that we don't behave like an Apache clone. It forces you not to rely on
peculiarities of one particular implementation. Also, remember that you
are interacting with mod_python, rather than Apache itself, so there is
a layer between you and the webserver proper that you will also have to
look at the documentation for.

On the Django side, have a look in django/core/handlers/ at modpython.py
and wsgi.py and you'll see how we populate the META variable in both
cases. As you can see there, a lot of the information, including the two
variables you are interested in, we simply copy directly from the
information provided by the server -- be it a WSGI-compatible
implementation or modpython.

After familiarising yourself with that code, you can then look further
into why you are not receiving the information you are after from the
web server in whichever setup you prefer.

Regards,
Malcolm


Graham Dumpleton

unread,
Apr 28, 2007, 7:24:38 PM4/28/07
to Django users
On Apr 29, 1:42 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

> On Sat, 2007-04-28 at 15:22 +0000, omat * gezgin.com wrote:
> > Because request.META['PATH_INFO'] is only available when running the
> > test server.
>
> > This is also a point of inconvenience and I think the test server
> > should be made more compatible with apache.
>
> Apache is not the only web server in the world, so it is a good thing
> that we don't behave like an Apache clone. It forces you not to rely on
> peculiarities of one particular implementation. Also, remember that you
> are interacting withmod_python, rather than Apache itself, so there is

> a layer between you and the webserver proper that you will also have to
> look at the documentation for.
>
> On the Django side, have a look in django/core/handlers/ at modpython.py
> and wsgi.py and you'll see how we populate the META variable in both
> cases. As you can see there, a lot of the information, including the two
> variables you are interested in, we simply copy directly from the
> information provided by the server -- be it a WSGI-compatible
> implementation or modpython.
>
> After familiarising yourself with that code, you can then look further
> into why you are not receiving the information you are after from the
> web server in whichever setup you prefer.

Because of the way mod_python hooks into Apache and the way people
then use that, you cannot rely on the value of SCRIPT_NAME and
PATH_INFO being correct. Even third party WSGI adapters which work on
top of mod_python don't necessarily set them correctly without some
hack involving the user manually specifying what the original
application mount point was. This situation could be improved if
direct adapters or WSGI adapters for mod_python made use of some new
APIs within the mod_python 3.3 core to properly determine the mount
point, but this will not help if you are using older versions of
mod_python.

If you wish to play with some pre-release code, the only WSGI system
for Apache (in the style of mod_python), that sets SCRIPT_NAME and
PATH_INFO correctly is mod_wsgi (http://www.modwsgi.org).

Graham

Reply all
Reply to author
Forward
0 new messages