而不是拖尾到i18n网址

而不是拖尾到i18n网址

本文介绍了404关于请求,而不是拖尾到i18n网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 APPEND_SLASH = True 将所有请求设置为/ whatever / path将被重定向到/ whatever / path /\".



中定义的网址i18n_patterns()不要因为某种原因重定向



甚至测试工作:

  ./ runtests.py --settings = test_sqlite i18n.URLRedirectWithoutTrailingSlashTests 


解决方案

如果中间件不顺序,它无法正常工作。 p>

看到:



这样做应该如下所示:

  MIDDLEWARE_CLASSES =(
'django .contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.Loca leMiddleware',
'django.middleware.common.CommonMiddleware',
...


Because of the APPEND_SLASH = True setting all requests with "/whatever/path" will be redirected to "/whatever/path/".

BUT urls definded within a i18n_patterns() don't redirect for some reason

even the test works:

./runtests.py --settings=test_sqlite i18n.URLRedirectWithoutTrailingSlashTests
解决方案

it doesn't work properly if the middleware's aren't in order.

see:https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-language-preference

that's how it should look like:

MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',
   ...
)

这篇关于404关于请求,而不是拖尾到i18n网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 18:09