Django url国际化不能在生产模式下工作 [英] Django url internationalization not working in production mode

查看:105
本文介绍了Django url国际化不能在生产模式下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django 1.4中编程有多语言支持(法语和英语)的站点。

i'm programming in django 1.4 a site with multilanguage support (french and english).

在调试模式下,一切正常。然后我转到生产模式(DEBUG = False),并且urls不再工作。

Everything works fine in debug mode. Then I pass to production mode (DEBUG=False) and the urls no longer work.

例:在调试模式下,当我请求页面/ agricole /,django自动重定向到/ fr / agricole。

Ex. : in debug mode, when I request the page /agricole/, django redirect automatically to /fr/agricole.

但在生产模式下,它会发送错误,不再重定向页面。

But in production mode, it sends a error and no longer redirect the page.

我已经搜索过网络,检查LocaleMiddleware,就像在django文档和所有内容中所述一样,但仍然失败。

I have searched the web, check the LocaleMiddleware, like said on django documentation and everything, but it still fails.

我不能在模板中进行硬编码/ fr / *,因为它会破坏多线程支持。
手写一个重定向器重定向,不干净。

I cannot hard code /fr/* in the templates, since it will break the multilingue support. And writting by hand a redirector who redirect, is not clean.

我想念什么?一个模板标签?一个url配置?

What do I miss? A template tag? a url config?

我的

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
)

和我的url.py

from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
from django.views.generic import RedirectView

admin.autodiscover()

import annonces.views as annonces

urlpatterns = i18n_patterns('',
    url(r'.*register/$', 'annonces.register', name='register'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'accounts/profile/$', RedirectView.as_view(url='/')),
    url(r'^favicon\.ico$', RedirectView.as_view(url='static/favicon.ico')),
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    (r'^accounts/', include('registration.backends.simple.urls')),
    (r'^tinymce/', include('tinymce.urls')),
    url(r'^longlat/(.*)$', 'annonces.longlat', name='longlat'),
    url(r'^', include('cms.urls')),
)


推荐答案

我发现这个问题的问题。
如果您有一些处理404页面的中间件,那么此页面必须重新生成状态404.如果它将返回状态,则i18n重定向将无法正常工作。

I found problem of this issue. if you have some middlewares that handle 404 page, then this page must retur status 404. If it will return othe status then i18n redirect will not work.

这篇关于Django url国际化不能在生产模式下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆