My project has this middleware setting:
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)
For local development, I setup a local_settings.py
module which redefines the middleware setting as:
MIDDLEWARE_CLASSES = (
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
Here I'm just removing the cache-related middleware, just for development.
In my Apache deploy, the local_settings.py
only redefines DEBUG
(to False
) and the DATABASES
dict.
I even installed IPython in the project's production virtualenv (the one that the Apache server uses) and executed this:
In [1]: from django.conf import settings
In [2]: settings.MIDDLEWARE_CLASSES
Out[2]:
('django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware')
But, despite all this, I still have to enter a language identifier in the URL (as httpp://mysite.com/en/myview/
) to access any URL that uses from django.conf.urls.i18n.i18n_patterns
. And one of the functions of django.middleware.locale.LocaleMiddleware
is to do precisely that, when accessing a localized view without a language code prefix, guess it from the user-agent headers and redirect to the prefixed view.
How to debug what's going on?