5

Once more: Django 1.10.

New middleware style. In the documentation we have:

https://docs.djangoproject.com/en/1.10/releases/1.10/#new-style-middleware

https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

I need Django Debug Toolbar. Release 1.5 is compatible with Django 1.10.

This is installation documentation: https://django-debug-toolbar.readthedocs.io/en/stable/installation.html

The Django Debug Toolbar needs:

MIDDLEWARE_CLASSES = [
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
] 

Well, I tried to add 'debug_toolbar.middleware.DebugToolbarMiddleware' to existing MIDDLEWARE. No success (the server doesn't run, some exceptions are risen).

Then I just renamed MIDDLEWARE into MIDDLEWARE_CLASSES. Working.

What troubles me: I can't find in the documentation that MIDDLEWARE_CLASSES is supported. But everything works.

Could you give me some piece of advice: is it Ok to use MIDDLEWARE_CLASSES settings or not? And where to read about this.

Trts
  • 985
  • 1
  • 11
  • 24

1 Answers1

0

Since Django 1.10 introduced new middleware style, existing middlewares should be updated. https://github.com/jazzband/django-debug-toolbar/issues/853

Your files should have content similar to the following:

prj/prj/settings.py

# { django-debug-toolbar
DEBUG_TOOLBAR_PATCH_SETTINGS = False
INTERNAL_IPS = ['127.0.0.1', ]
if DEBUG:
    # MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware',]
    MIDDLEWARE += ['test_app.crutch.AdaptedTo110DebugMiddleware',]
    INSTALLED_APPS += ['debug_toolbar',]
# } django-debug-toolbar

prj/prj/urls.py

from django.conf import settings # for django-debug-toolbar
# { django-debug-toolbar
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]
# } django-debug-toolbar

prj/test_app/crutch.py

# a crutch for the debugger
from django.utils.deprecation import MiddlewareMixin
from debug_toolbar.middleware import DebugToolbarMiddleware


class AdaptedTo110DebugMiddleware(MiddlewareMixin, DebugToolbarMiddleware):
    pass
yoniLavi
  • 2,624
  • 1
  • 24
  • 30
Aleks V
  • 29
  • 5