Language specific redirection

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?

Answers


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.


Need Your Help

Hide table on mouseout using javascript

javascript html

I am creating a dynamic web page using Javascript, in which I am creating multiple tables with contents listed in each. Initially with table 1 the page loads, When I mouseover on particular item on...

Error when deleting from an NSFetchedResultsController controlled UITableView outside of the table view

uitableview nsfetchedresultscontroller

I'm trying to remove an object managed by an NSFetchedResultsController in a UITableView - and I'm attempting to do so from a separate view via add/remove buttons. However, it seems as though cont...