user4032117
user4032117

Reputation: 41

Django url internationalization not working in production mode

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

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

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.

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

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.

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

My

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',
)

and my 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')),
)

Upvotes: 4

Views: 1119

Answers (1)

Andrey Nikishaev
Andrey Nikishaev

Reputation: 3882

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.

Upvotes: 4

Related Questions