6

Django 1.10

django-debug-toolbar==1.5

I am working on a new project (I've just installed Django). Trying to install Django Debug Toolbar.

Documentation: https://django-debug-toolbar.readthedocs.io/en/stable/installation.html#prerequisites

According to the documentation, this release of the django-debug-toolbar is compatible with Django 1.10.

What have I done wrong?

settings.py

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

urls.py

from django.conf import settings
from django.conf.urls import include
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]

Traceback

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f97d6ab9840>
Traceback (most recent call last):
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/michael/workspace/photoarchive/photoarchive/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/home/michael/workspace/venv/photoarchive/lib/python3.5/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given

3 Answers 3

12

Django 1.10 introduced new style of middleware:

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

There was a bug in django-debug-toolbar related to that change. The bug is now fixed in version 1.6 or later, so just use the latest version released to PyPI.


If you must use versions of django-debug-toolbar older than 1.6 with Django 1.10 or later, you can change MIDDLEWARE to MIDDLEWARE_CLASSES in the Django settings.

Sign up to request clarification or add additional context in comments.

Comments

3

I changed MIDDLEWARE to MIDDLEWARE_CLASSES in settings.py. It's work for me!

2 Comments

You should really add some explanation as to why this should work - in its current form, your answer does not provide any explanation which can help the rest of the community to understand what you did to solve/answer the question. Specifically, you need to explain how these settings make it work.
If you change MIDDLEWARE to MIDDLEWARE_CLASSES the value of MIDDLEWARE_CLASSES is ignored. This is the warning i get: WARNINGS: ?: (1_10.W001) The MIDDLEWARE_CLASSES setting is deprecated in Django 1.10 and the MIDDLEWARE setting takes precedence. Since you've set MIDDLEWARE, the value of MIDDLEWARE_CLASSES is ignored. So that's the reason he can run it... Official documentation: docs.djangoproject.com/en/dev/releases/1.10/…
1

Already fixed. There is no need to rename MIDDLEWARE. Just install directly from git:

pip install https://github.com/jazzband/django-debug-toolbar/archive/master.zip

And instead of stable use the latest docs: http://django-debug-toolbar.readthedocs.io/en/latest/

1 Comment

As of Sept. 29, when using the recommended Explicit Setup, the regular old pip install version from PyPI doesn't work. Installing from github as above does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.