79514886

Date: 2025-03-17 14:38:25
Score: 1
Natty:
Report link

Adding to @matino's answer - if you want to maintain the order of the middleware (which you typically want to do). You can splice the original middleware tuple and make a new one with the new order. Let's say you want your debug middleware sitting just in front of your session middleware, you'd use the following in your dev.py:

sessionMiddlewareIndex = MIDDLEWARE_CLASSES.index('django.contrib.sessions.middleware.SessionMiddleware')
MIDDLEWARE = MIDDLEWARE[:sessionMiddlewareIndex] \
    + ('debug_toolbar.middleware.DebugToolbarMiddleware',) \
    + MIDDLEWARE[sessionMiddlewareIndex:]
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @matino's
  • Low reputation (1):
Posted by: Candace Wong