Django 1.10 and Middleware

Once again: Django 1.10.

The new style of the middle layer. The documentation has:

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 a Debug Django toolbar. Version 1.5 is compatible with Django 1.10.

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

Django Debug Toolbar:

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

Well, I tried adding 'debug_toolbar.middleware.DebugToolbarMiddleware' to an existing MIDDLEWARE. No success (server does not start, some exceptions are raised).

Then I just renamed MIDDLEWARE to MIDDLEWARE_CLASSES. Working.

: , MIDDLEWARE_CLASSES. .

: MIDDLEWARE_CLASSES ? .

+4
1

Django 1.10 , . https://github.com/jazzband/django-debug-toolbar/issues/853

, :

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
0

Source: https://habr.com/ru/post/1650345/


All Articles