没有尾部斜杠的i18n URL请求返回404
因为设置了 APPEND_SLASH = True
,所以所有像 "/whatever/path" 这样的请求都会被重定向到 "/whatever/path/"。
但是,在 i18n_patterns()
中定义的 URL 出于某种原因不会被重定向。
即使测试也能正常工作:
./runtests.py --settings=test_sqlite i18n.URLRedirectWithoutTrailingSlashTests
1 个回答
20
如果中间件的顺序不对,它就不能正常工作。
你可以查看这个链接了解更多信息:https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-language-preference
它应该是这样的:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
)