Change language prefix in the URL of rendered page in a view

6 views
Skip to first unread message

jul

unread,
Apr 13, 2010, 2:48:57 PM4/13/10
to django-multilingual
hi,

I'm doing some IP localization and need to set the language in a view.
Using translation.activate changes the language, but the rendered page
still have the default language prefix in its URL.
Is there any way to also change the rendered URL?

thanks
jul

jul

unread,
Apr 13, 2010, 2:50:57 PM4/13/10
to django-multilingual
I've just noticed there is a common group for localeurl and
multilingual. This one is about localeurl!
jul

Carl Meyer

unread,
Apr 13, 2010, 10:42:22 PM4/13/10
to django-multilingual
Hi jul,

A URL is not "rendered," it is requested by the browser. Once the
browser has requested a given URL you can't change it from the server
side. What you can do is return an HTTP redirect to a different URL.
(In this case there's no point in using translation.activate(), all
you need to do is make sure the URL you are redirecting to has the
proper language prefix). django-localeurl's built-in change_locale
view handles all this for you, I recommend you just use that.

Carl

jul

unread,
Apr 14, 2010, 5:18:22 AM4/14/10
to django-multilingual
Thank you Carl.
A redirect does what I want. The only problem is that it creates a
redirect loop.
I set some session variable to avoid that.

jul

Reply all
Reply to author
Forward
0 new messages