擅长:python、mysql、java
<p>这是一个旧的bug,在这里被跟踪到:</p>
<p><a href="https://code.djangoproject.com/ticket/17734" rel="nofollow noreferrer">https://code.djangoproject.com/ticket/17734</a></p>
<p>404错误处理程序是Django的默认处理程序。为了翻译“找不到”的信息,它显然考虑了当前的语言。在</p>
<p>除非可以升级到新版本,否则可能需要定义自己的错误处理程序(包括route/url)。在</p>
<p>编辑:</p>
<p>作为一种解决方法,可以扩展LocaleMiddleware,也可以扩展CommonMiddleware。然而,404处理程序仍然可以发挥它的魔力。也许值得一试,因为它只需要几行代码。在</p>
<p>引用罚单:</p>
<blockquote>
<p>when you request /api/raising/404/, it is redirecting the user to /en/api/raising/404/ (assuming it detects the language as en). If it tests before redirecting the user if /en/api/raising/404/ is resolvable, it would find out that this would raise a 404 as well and thus would not redirect the user.</p>
</blockquote>
<p>编辑2:</p>
<p>作为一种替代方法,您可以不使用<code>i18n_patterns</code>,而只需通过browser/cookie/parameter检测/切换语言。我在一个项目(包括Django CMS)中这样做,在那里我一直遇到这些url的问题。本地化的Django站点使用i18nurl模式绝对不是先决条件。这只是上面的东西,但一点也不必要。没有它,本地化将很好地工作。如果您需要有关切换语言的中间件的帮助,请发表评论。在</p>