DEV Community

Borhan Tipu
Borhan Tipu

Posted on • Updated on

Django Debug Toolbar, not showing/appearing, Fix it & Bring it Back.

Alt Text

Are you facing the problem with Django Debug Toolbar showing up?
I faced too…
Here I will show you how I fixed it….

Install Debug Toolbar…
For virtual env: pip install django-debug-toolbar
For Pipenv: pipenv install django-debug-toolbar

Link: https://pypi.org/project/django-debug-toolbar/
Docs: https://django-debug-toolbar.readthedocs.io/en/latest/

Go to settings.py and add to INSTALLED_APPS



INSTALLED_APPS = [
 # …
 'django.contrib.staticfiles',
 # … not for debug mode
 'debug_toolbar',
]
STATIC_URL = '/static/'


Enter fullscreen mode Exit fullscreen mode

The Debug Toolbar should have appeared only in Debug mode. So, the rest of the settings will be for DEBUG mode only.



# debug_toolbar moved here. 
if DEBUG:
    MIDDLEWARE += [
        'debug_toolbar.middleware.DebugToolbarMiddleware',
    ]
    INSTALLED_APPS += [
        'debug_toolbar',
    ]
    INTERNAL_IPS = ['127.0.0.1', ]

    # this is the main reason for not showing up the toolbar
    import mimetypes
    mimetypes.add_type("application/javascript", ".js", True)

    DEBUG_TOOLBAR_CONFIG = {
        'INTERCEPT_REDIRECTS': False,
    }


Enter fullscreen mode Exit fullscreen mode

Update your {project}/urls.py file.



from django.conf import settings
from django.urls import path, include
urlpatterns = [
  path("admin/", admin.site.urls),
]
# add debug toolbar in urlpatterns
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls)),
    ]


Enter fullscreen mode Exit fullscreen mode

The main reason for not showing up the toolbar is because of the javascript mime-types error when you connect the debug_toolbar
If the already added to your application then just add two lines of code in your settings.py file.



import mimetypes
mimetypes.add_type("application/javascript", ".js", True)


Enter fullscreen mode Exit fullscreen mode

Now the debug toolbar should be visible in Debug mode.

Medium Link: Django Debug Toolbar Fix


If you need any help with Full-Stack Development with Django and Shopify, feel free to contact me anytime.
Visit: imtipu.me
Contact if you need any help with Django and Shopify
Thanks!

Top comments (6)

Collapse
 
tombohub profile image
tombohub

mimetypes need to change to import mimetypes

Collapse
 
dionnyprensa profile image
Dionny Prensa

Thanks a lot!!!!!!!

Collapse
 
tipu profile image
Borhan Tipu

Welcome

Collapse
 
asif_iqbal profile image
Mohamed Asif Iqbal

Thank you for this!

Collapse
 
pinggolid profile image
pinggol-id

Hello,
I follow exactly per your guide but I am still facing error when I add ImageField in my Django models.Model
Here is my conda list:

Name Version Build Channel

appdirs 1.4.4 pyh9f0ad1d_0 conda-forge
asgiref 3.4.1 pyhd3eb1b0_0 anaconda
async-timeout 4.0.2 pypi_0 pypi
attrs 22.2.0 pyh71513ae_0 conda-forge
autobahn 23.1.2 pyhd8ed1ab_0 conda-forge
automat 22.10.0 pyhd8ed1ab_0 conda-forge
bcrypt 3.2.0 py311h2bbff1b_1
beautifulsoup4 4.12.2 pyha770c72_0 conda-forge
brotlipy 0.7.0 py311h2bbff1b_1002
bzip2 1.0.8 he774522_0
ca-certificates 2023.5.7 h56e8100_0 conda-forge
certifi 2023.5.7 pyhd8ed1ab_0 conda-forge
cffi 1.15.1 py311h2bbff1b_3
channels 4.0.0 pyhd8ed1ab_0 conda-forge
charset-normalizer 2.0.4 pyhd3eb1b0_0
click 8.0.3 pyhd3eb1b0_0 anaconda
constantly 15.1.0 py_0 conda-forge
crispy-bootstrap5 0.7 pypi_0 pypi
cryptography 39.0.1 py311h21b164f_0
daphne 3.0.2 pyhd8ed1ab_0 conda-forge
django 3.2.5 pyhd3eb1b0_0 anaconda
django-bootstrap5 23.1 pyhd8ed1ab_0 conda-forge
django-cors-headers 3.14.0 pyhd8ed1ab_0 conda-forge
django-crispy-forms 2.0 pyhd8ed1ab_0 conda-forge
django-debug-toolbar 4.1.0 pyhd8ed1ab_0 conda-forge
django-environ 0.4.5 py_1 conda-forge
django-lifecycle 1.0.0 pypi_0 pypi
django-redis 5.2.0 pypi_0 pypi
djangorestframework 3.14.0 pyhd8ed1ab_0 conda-forge
djangorestframework_simplejwt 4.4.0 py_0 conda-forge
freetype 2.10.4 h546665d_1 conda-forge
gdal 3.4.3 pypi_0 pypi
geos 3.11.0 h39d44d4_0 conda-forge
hyperlink 21.0.0 pyhd3deb0d_0 conda-forge
idna 3.4 pyhd8ed1ab_0 conda-forge
importlib-metadata 2.0.0 py_1 conda-forge
incremental 22.10.0 pyhd8ed1ab_0 conda-forge
jpeg 9e h8ffe710_2 conda-forge
krb5 1.19.4 h5b6d351_0 anaconda
lerc 3.0 hd77b12b_0
libdeflate 1.17 h2bbff1b_0
libffi 3.4.2 hd77b12b_6
libpng 1.6.39 h8cc25b3_0
libpq 12.9 hb652d5d_3 anaconda
libtiff 4.5.0 h8a3f274_0
libwebp 1.2.4 h2bbff1b_0
libwebp-base 1.2.4 h2bbff1b_1
lz4-c 1.9.3 h8ffe710_1 conda-forge
openrouteservice 2.3.3 0 michaelsjp
openssl 1.1.1t h2bbff1b_0
packaging 23.1 pypi_0 pypi
pillow 9.4.0 py311hd77b12b_0
pip 23.0.1 py311haa95532_0
proj4 5.2.0 ha925a31_1 anaconda
psycopg2 2.9.3 py311hcd4344a_0
pyasn1 0.4.8 py_0 conda-forge
pyasn1-modules 0.2.7 py_0 conda-forge
pycparser 2.21 pyhd8ed1ab_0 conda-forge
pyhamcrest 2.0.4 pyhd8ed1ab_0 conda-forge
pyjwt 1.7.1 pypi_0 pypi
pyopenssl 23.1.1 pyhd8ed1ab_0 conda-forge
pysocks 1.7.1 py311haa95532_0
python 3.11.0 h966fe2a_3
python-dotenv 0.21.0 py311haa95532_0
pytz 2021.3 pyhd3eb1b0_0 anaconda
pywin32 305 py311h2bbff1b_0
redis 4.5.5 pypi_0 pypi
requests 2.28.1 py311haa95532_1
service_identity 18.1.0 py_0 conda-forge
setuptools 65.6.3 py311haa95532_0
six 1.16.0 pyh6c4a22f_0 conda-forge
soupsieve 2.3.2.post1 pyhd8ed1ab_0 conda-forge
sqlite 3.41.2 h2bbff1b_0
sqlparse 0.4.1 py_0 anaconda
tk 8.6.12 h2bbff1b_0
twisted 22.2.0 py311h2bbff1b_1
twisted-iocpsupport 1.0.2 py311h2bbff1b_0
txaio 23.1.1 pyhd8ed1ab_0 conda-forge
typing_extensions 4.1.1 pyh06a4308_0 anaconda
tzdata 2023c h04d1e81_0
urllib3 1.26.15 py311haa95532_0
urlman 2.0.1 pypi_0 pypi
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
wheel 0.38.4 py311haa95532_0
whitenoise 6.4.0 pyhd8ed1ab_0 conda-forge
win_inet_pton 1.1.0 py311haa95532_0
wincertstore 0.2 py311haa95532_0
xz 5.2.10 h8cc25b3_1
zipp 3.15.0 pyhd8ed1ab_0 conda-forge
zlib 1.2.13 h8cc25b3_0
zope 1.0 py311haa95532_1
zope.interface 5.4.0 py311h2bbff1b_0
zstd 1.4.9 h6255e5f_0 conda-forge

Please help.

Collapse
 
tipu profile image
Borhan Tipu

need some Screenshots while debug mode is enabled.