20

When I try running the project, Django can not load the django-debug-toolbar plugin for some reason. Error message says:

web_1  | ModuleNotFoundError: No module named 'debug_toolbar'

Here is my settings.py

INSTALLED_APPS = [
    # ...
    'django.contrib.staticfiles',
    # ...
    'debug_toolbar',
]

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

INTERNAL_IPS = ('127.0.0.1', '192.168.0.1',)
Jrog
  • 1,469
  • 10
  • 29
Browning M.
  • 411
  • 1
  • 3
  • 12
  • Did you install `django-debug-toolbar` package? Please post your virtual environment requirements. – Jrog Feb 04 '19 at 10:05
  • Django>=2.0,<3.0 psycopg2>=2.7,<3.0 – Browning M. Feb 04 '19 at 14:45
  • I need more information. When does error be raised? `runserver` on your localhost? Or deployment? Are you using docker? If you are, please post your docker settings. – Jrog Feb 04 '19 at 14:52
  • The Error raise as soon as i add debug_toolbar on my installed_apps. yes im using docker on my localhost. This is what is in my docker-compose.yml: version: '3' services: db: image: postgres web: build: . command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - "8000:8000" depends_on: - db – Browning M. Feb 04 '19 at 15:46
  • Show your urls.py, please – Jorge Mauro Nov 25 '21 at 13:41

5 Answers5

26

If you have not installed the django-debug-toolbar package you can install it with help of the below command:

pip install django-debug-toolbar
Javad
  • 2,033
  • 3
  • 13
  • 23
vinodsesetti
  • 368
  • 2
  • 6
5

I had to re-install django-debug-toolbar by adding it to requirements.txt and then running:

docker-compose build web

After doing that, the toolbar wasn't still showing. I had to add this code to the settings.py file

def show_toolbar(request):
    return True

DEBUG_TOOLBAR_CONFIG = {
  "SHOW_TOOLBAR_CALLBACK" : show_toolbar,
}

Answered here: https://stackoverflow.com/a/10518040/11011598

Javad
  • 2,033
  • 3
  • 13
  • 23
Browning M.
  • 411
  • 1
  • 3
  • 12
1

You can use the below command which worked perfectly for me:

$ python -m pip install -e git+https://github.com/jazzband/django-debug-toolbar.git#egg=django-debug-toolbar
Javad
  • 2,033
  • 3
  • 13
  • 23
jbcloud29
  • 11
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 13 '22 at 11:12
1

I did run across the same problem when trying to use debug toolbar with Django & docker.

The solution posted above did not solve the problem entirely. The toolbar was sometimes not visible on the rest_framework browsable API.

I solved the problem by adding the below into my settings.py

INTERNAL_IPS = ['127.0.0.1',"0.0.0.0:8000"] 

import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS += [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips]

ref: https://knasmueller.net/fix-djangos-debug-toolbar-not-showing-inside-docker

Javad
  • 2,033
  • 3
  • 13
  • 23
0

I ran across this issue because we're using docker containers for the development environment and we're also using Pipenv to manage deps. Silly me, I did:

pipenv install django-debug-toolbar --dev

When in my environment this does no good because it will never be installed on my docker container environment. I had to reinstall without the --dev part and it worked fine afterwards.

Hope this helps someone out in the same situation.

Harlin
  • 1,059
  • 14
  • 18