Chris
Chris

Reputation: 223

I cannot get django debug toolbar to appear in the browser. Project is attached

Its a very simple small project located here https://github.com/cbaldwin20/project_8/tree/master/project_eight

I tried for like two hours to get the 'django debug toolbar' to appear in the browser with no success. I'm not sure if its my code or my computer. Thanks for any help.

Upvotes: 1

Views: 5385

Answers (4)

Ananthu B
Ananthu B

Reputation: 1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
         "code goes here"
        *{
             display: block !important;
         }
    </style>
</head>

Just use the style below. 👍

* {
     display: block !important;
 }

In the last part of of that page, you are rendering

https://github.com/pydanny/cookiecutter-django/commit/c35a2ece8a734a7f42138f84203e3f6cce72c6bd

.djdt-hidden {
                 display: block !important;
             }

Upvotes: -1

rimvy
rimvy

Reputation: 11

I'm developing in docker containers, so my case might be a little bit different than yours, but that's the only solution which worked for me.

urls.py

if settings.DEBUG:
    import debug_toolbar
    urlpatterns.insert(0, path('__debug__/', include(debug_toolbar.urls)))

settings.py

if DEBUG:
    MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware')

if DEBUG:
    INSTALLED_APPS.append('debug_toolbar')

And that's the most important part from settings.py which made it to finally appear.

if DEBUG:
    INTERNAL_IPS = type(str('c'), (), {'__contains__': lambda *a: True})()

Upvotes: 1

Anup Yadav
Anup Yadav

Reputation: 3005

replace urls.py from

if settings.DEBUG:
    import debug_toolbar

to

urlpatterns = [
    path('', include('minerals.urls', namespace="minerals")),
    path('admin/', admin.site.urls),    
]

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

commented INTERNAL_IPS = ["127.0.0.1"] This is important

remove STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ]

Upvotes: 4

JPG
JPG

Reputation: 88689

add this in settings.py

DEBUG_TOOLBAR_CONFIG = {
    'SHOW_TOOLBAR_CALLBACK': 'settings.show_toolbar'
}
INSTALLED_APPS += ['debug_toolbar']
MIDDLEWARE_CLASSES = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE_CLASSES

Update
I think I was little rush to the answer, sorry for that.

Changes :

1: removed this from settings.py

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]


2: added INTERNAL_IPS = ['127.0.0.1'] to settings

3: changed project_8/urls.py as below,

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url

from django.conf import settings

urlpatterns = [
    path('', include('minerals.urls', namespace="minerals")),
    path('admin/', admin.site.urls),

]

if settings.DEBUG:
    import debug_toolbar

    urlpatterns = [
                      url(r'^__debug__/', include(debug_toolbar.urls)),
                  ] + urlpatterns


Upvotes: 2

Related Questions