I implemented the user login/registration using Django’s authentication system but hit the wall and hopefully someone can help me.
This website is using django-localeurl and is presently running in 3 languages.
I’m having problems passing the login redirect to the right language.
What I want to do is pass the current language to the LOGIN_REDIRECT_URL variable (in settings.py), so that instead of having:
LOGIN_REDIRECT_URL = '/accounts/my_account/'
I’d have something like:
LOGIN_REDIRECT_URL = '/%s/accounts/my_account/' % request.LANGUAGE_CODE
which of course doesn’t work because I’m not passing requests to settings.py.
Is there a really really easy and smart way to do this? It always defaults to English and that’s a big problem. If a user is viewing the site in Spanish, once they login they’re redirected to English :/
I have languages setup like this:
gettext = lambda s: s
LANGUAGES = (
('pt', gettext('Portuguese')),
('es', gettext('Spanish')),
('en', gettext('English')),
)
and
LANGUAGE_CODE = 'en'
because the admin needs to be in English.
Can anyone help?
Thanks!
For my own projects of that kind, I use my own login_redirect decorator instead of the one provided by Django, which always sent me to the static url defined in settings.py. My i18n decorator looks like that: