python - @login_required is losing the current specified language -


i using i18n_patterns internationalize app , it's working except when click on link requires login (a view protected @login_required decorator), being redirected login form in default language instead of active one.

how can preserve active url? in other words, when in french section, want @login_required redirect me /fr/login/?next=/fr/clients/ instead of /en/login/?next=/fr/clients/

i'm not well-versed in i18n django, don't think possible because login_required binds login_url parameter decorated function @ point of decorator application. you're better off writing own decorator; assuming don't use either of optional parameters login_required, can make own as

from django.contrib.auth.views import redirect_to_login django.core.urlresolvers import reverse import functools  def login_required(fn):     @functools.wraps(fn)     def _decorated(request, *args, **kwargs):         if request.user.is_authenticated():             return fn(request, *args, **kwargs)          path = request.get_full_path()         login_url = reverse('login')         return redirect_to_login(path, login_url) 

where reverse('login') gets whatever name of login view in urls.py is.

i haven't tested this, if comes i'll try debug best of ability.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -