我正在使用https://github.com/carljm/django-localeurl包来使我的网站使用多种语言。
settings.py
LANGUAGE_CODE = 'en'
_ = lambda s: s
LANGUAGES = (
('lt', _("Lithuanian")),
('en', _("English")),
)
PREFIX_DEFAULT_LOCALE = False
any_other_file.py
from django.utils import translation
def my_view(request):
translation.activate('en')
print reverse('some_url_name') # /my-url/
translation.activate('lt')
print reverse('some_url_name') # /lt/my-lithuanian-url/
# so far so good
translation.activate('en')
redirect(reverse_lazy('some_url_name')) # redirects to /my-url/
translation.activate('lt')
redirect(reverse_lazy('some_url_name')) # tries to redirect to /my-lithuanian-url/ without /lt/ prefix which results in Http404 error
如何修复项目中许多地方使用的所有惰性URL反向函数?