views:

139

answers:

0

Good morning everyone,

Introduction

I Got a question about localeURL usage. Everything works great for me with url like this : http://www.mysite.com/

problem

But my application use apache as server, with mod_wsgi. The httpd.conf script contains this line :

WSGIScriptAlias /MY_PREFIX /path/to/django/app/apache/django.wsgi

that gives url like this :
http://www.mysite.com/MY_PREFIX/

The same problem occured with the change_locale view. I modified this code in order to manage this prefix (store in settings.SERVER_PREFIX) :

    def change_locale(request) :
    """
    Redirect to a given url while changing the locale in the path
    The url and the locale code need to be specified in the
    request parameters.
    O. Rochaix; Taken from localeURL view, and tuned to manage :            
        - SERVER_PREFIX from settings.py
    """
    next = request.REQUEST.get('next', None)
    if not next:
        next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = settings.SERVER_PREFIX + '/'

    next = urlsplit(next).path

    prefix = False
    if settings.SERVER_PREFIX!="" and next.startswith(settings.SERVER_PREFIX) :
        prefix = True
        next = "/" + next.lstrip(settings.SERVER_PREFIX) 

    _, path = utils.strip_path (next)

    if request.method == 'POST':
        locale = request.POST.get('locale', None)
        if locale and check_for_language(locale):
            path = utils.locale_path(path, locale)

    if prefix :
        path = settings.SERVER_PREFIX + path

    response = http.HttpResponseRedirect(path)
    return response

with this customized view, i'm able to correctly change language, but i'm not sure that's the right way of doing stuff.

Question

  1. when, in httpd.conf you use WSGIScriptAlias with /PREFIX (ie "/Blog"), do we need, on python side to use a variable (here settings.SERVER_PREFIX) that match WSGIScriptAlias ? i use it for MEDIA_URL and other stuff, but maybe there is some configuration to do in order to make it work "automatically" without having to manage this on python side

  2. Do you think that this customized view (change_locale) is the right way to manage this issue ? Or is there some kind of automagic stuff as for 1. ?

  3. It doesn't solve the problem if I type the adress (http://www.mysite.com/MY_PREFIX/) in adress bar. If customization is the way to go, i will change this as well, but I think there is a better solution !

Thanks in advance !