Django Embedded Middleware Default List

Django comes with a list of embedded middleware , but if you want to use all (or most) of them, it has to work through tons of documents to get the correct sorting in the settings.py file.

Is there an optimal default order for all the built-in classes of Django 1.1? Ie, copy something 'paste into settings.py:

MIDDLEWARE_CLASSES = ( # perfect order here please ;-) ) 

Alternative answer: Are there several possible orders and what's the difference?

By the way: the order is significant, but I only know some of the default dependencies, like SessionMiddleware before AuthenticationMiddleware.

+4
source share
1 answer

They have a default list for the underlying Django middleware:

 MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) 

Any others that you create or receive from third parties can be added at the end of the tuple above. The Django book also mentions that when you request to view an order from CommonMiddleware to AuthenticationMiddleware and finally to your view. The reverse response reverses the order from AuthenticationMiddleware to CommonMiddleware . Here's the doc for him.

In response to the comment:

After flashing Django tickets, it seems like it was a problem with the Django dev community, and I don't think there is a final answer to it yet. Here is a ticket that contains a discussion along with the part where Jacob closed it. You might want to try this problem again as a Django ticket to get an official response from the developer.

+9
source

All Articles