sezione

Switch language

Hi everyone and welcome to my first blog post! Today I want to share to you a small snippet I am using to switch language on the websites I am working on. It works well with django-localeurl and it allows you to have a unique view to switch between languages without leaving the current page.

Enough chit-chat, there it is the code:

from django.http import HttpResponseRedirect
def switch_language(request, language):
    request.session['django_language'] = language
    if request.META.has_key('HTTP_REFERER'):
        referer= '/' + '/'.join(request.META['HTTP_REFERER'].split('/')[4:])
    else:
        referer= '/'
    return HttpResponseRedirect(referer)

Posted on marzo 19, 2009

About

Brokenseal รจ Davide Callegari, un giovane professionista con la passione per la programmazione e il web design.

Tag cloud

Archive

Credits

ponybadge

Django powered Portfolio