Table 17.1 provides some hints about the ordering of various Django middleware classes:
Class |
Notes |
---|---|
UpdateCacheMiddleware |
Before those that modify the |
GZipMiddleware |
Before any middleware that may change or use the response body. After |
ConditionalGetMiddleware |
Before |
SessionMiddleware |
After |
LocaleMiddleware |
One of the topmost, after |
CommonMiddleware |
Before any middleware that may change the response (it calculates After Close to the top: it redirects when |
CsrfViewMiddleware |
Before any view middleware that assumes that CSRF attacks... |