syv
syv

Reputation: 3608

Set session value in Template Django

I'm building an application which supports Multi-Lingual. So I have to keep track the Language option that is chosen by the user in browser and send that to View to load appropriate template. What is the best practice available?

Can I use default browser session to achieve this? If so how to set the value in template?

Upvotes: 0

Views: 1472

Answers (1)

Bit68
Bit68

Reputation: 1546

I would personnaly use the following view function:

def changeLang(request):
    request.session['lang'] = request.GET['lang'] #'en/' or 'fr/' etc...
    return render_to_response(request.session['lang'] + 'home.html', {}, RequestContext(request))

Where I have my templates folder ready for the different options for lang. I'm quite aware that django supports internationalization, but it's always more accurate to build a version for each language, especially if one of them is a Right To Left language, which is my case.

Upvotes: 1

Related Questions