views:

36

answers:

1

I want to ignore the post form in the django's internatonalization.

I am using the django-multilingual app, so I have different fields for different languages in the db.

I come up with this idea: For each language, from the index.html page, redirect to a different url (e.g. /en/ or /de/ or /zh/). And each view of this urls, set the session according to the language like this:

def set_lang_en(request):
   request.session['django_language'] = 'en'
   render_to_response("home.html")

def set_lang_zh(request):
   request.session['django_language'] = 'zh-cn'
   render_to_response("home.html")

Interestingly, this does the job, but if i refresh the page again after redirection (home.html).

Why it is like this? And how can solve this problem either in my direction or other one?

+1  A: 

multilingual.middleware reads language code from session long before you set it in your view. You can change language in your view once more:

from multilingual.languages import set_default_language
set_default_language('en')

Or if you only want to get rid of method post do not render home template in your view but set cookie and redirect user back.

alex vasi