Good morning everyone,
Introduction
I Got a question about localeURL usage. Everything works great for me with url like this : http://www.mysite.com/
If I type http://www.mysite.com/ in adress bar, it turns correctly in http://www.mysite.com/en/ for example.
If I use the view change_locale, it's also all right (ie change www.mysite.com/en/ in www.mysite.com/fr/).
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/
- If I type http://www.mysite.com/MY_PREFIX/ in the adress bar, the adress turns into http://www.mysite.com/en/ when the expected result should be http://www.mysite.com/MY_PREFIX/en/
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
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
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. ?
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 !