Skip to content

Commit 388e177

Browse files
committed
Make DebugToolarMiddleware compatible with Django 1.10's MIDDLEWARE setting
Fixes #853.
1 parent 96b5c48 commit 388e177

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

debug_toolbar/middleware.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
from django.conf import settings
1111
from django.utils import six
1212
from django.utils.encoding import force_text
13+
from django.utils.functional import cached_property
1314
from django.utils.module_loading import import_string
1415

1516
from debug_toolbar import settings as dt_settings
1617
from debug_toolbar.toolbar import DebugToolbar
1718

19+
try:
20+
from django.utils.deprecation import MiddlewareMixin
21+
except ImportError: # Django < 1.10
22+
# Works perfectly for everyone using MIDDLEWARE_CLASSES
23+
MiddlewareMixin = object
24+
25+
1826
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
1927

2028

@@ -31,21 +39,22 @@ def show_toolbar(request):
3139
return bool(settings.DEBUG)
3240

3341

34-
class DebugToolbarMiddleware(object):
42+
class DebugToolbarMiddleware(MiddlewareMixin):
3543
"""
3644
Middleware to set up Debug Toolbar on incoming request and render toolbar
3745
on outgoing response.
3846
"""
3947
debug_toolbars = {}
4048

41-
def __init__(self):
49+
@cached_property
50+
def show_toolbar(self):
4251
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
4352
# setup, resolve it to the corresponding callable.
4453
func_or_path = dt_settings.get_config()['SHOW_TOOLBAR_CALLBACK']
4554
if isinstance(func_or_path, six.string_types):
46-
self.show_toolbar = import_string(func_or_path)
55+
return import_string(func_or_path)
4756
else:
48-
self.show_toolbar = func_or_path
57+
return func_or_path
4958

5059
def process_request(self, request):
5160
# Decide whether the toolbar is active for this request.

docs/changes.rst

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Change log
22
==========
33

4+
1.6 (upcoming)
5+
--------------
6+
7+
Removed features
8+
~~~~~~~~~~~~~~~~
9+
10+
* Support for automatic setup has been removed. Installation now requires
11+
explicit setup. As a result, the ``DEBUG_TOOLBAR_PATCH_SETTINGS`` setting has
12+
also been removed. See the :doc:`installation documentation <installation>`
13+
for details.
14+
15+
Bugfixes
16+
~~~~~~~~
17+
18+
* The ``DebugToolbarMiddleware`` now also supports Django 1.10's ``MIDDLEWARE``
19+
setting.
20+
421
1.5
522
---
623

0 commit comments

Comments
 (0)