11

I'm using the new i18n_patterns of Django 1.4:

from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns

from django.contrib import admin
admin.autodiscover()

urlpatterns += i18n_patterns('',
    url(r'^admin/', include(admin.site.urls)),
)

It works for every active language:

/en/admin/ # Ok
/es/admin/ # Ok

But this fails:

/admin/ # 404 Not found

How to avoid the 404 error and redirect to a language-prefixed version of the requested URL (not only the admin panel)?

Is to write a custom middleware the solution? Why this doesn't come by default in Django?

jpic
  • 32,891
  • 5
  • 112
  • 113
Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45

1 Answers1

17

It looks like you did not enable django.middleware.locale.LocaleMiddleware.

jpic
  • 32,891
  • 5
  • 112
  • 113
  • 2
    Oops... My bad! I guess the docs needs to clarify this a little more. However after reading the whole translation section it becomes clear that `django.middleware.locale.LocaleMiddleware` is pretty much needed for everything on translation. Thanks! – Armando Pérez Marqués Jun 12 '12 at 02:59
  • Answer still applies to Django 1.9. – jjmontes Feb 11 '16 at 01:09