Django Middleware Order

I got stung by this today. I was presented with the following error:

The Django remote user auth middleware requires the authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert ‘django.contrib.auth.middleware.AuthenticationMiddleware’ before the RemoteUserMiddleware class.

Even though my MIDDLEWARE_CLASSES complied with the request above:

MIDDLEWARE_CLASSES = (

‘django.middleware.common.CommonMiddleware’, ‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.contrib.auth.middleware.RemoteUserMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’,

)

Re-Ordered to:

MIDDLEWARE_CLASSES = ( ‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.middleware.common.CommonMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.RemoteUserMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’, )

And the error went away :-/