1

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.

Chris
  • 223
  • 4
  • 12

4 Answers4

4

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'), ]

Chris
  • 223
  • 4
  • 12
Anup Yadav
  • 2,825
  • 3
  • 21
  • 30
  • I don't understand, you first said I need to add the second block of code, but then told me to remove `url(r'^__debug__/', include(debug_toolbar.urls))` which you told me above to add.... – Chris Feb 28 '18 at 11:29
  • 1
    It is already added at your line no. 29, you remove that and keep mine of if condition – Anup Yadav Feb 28 '18 at 11:30
  • it says 'name 'urlpatterns' is not defined'. On the `+ urlpatterns` it shows an error – Chris Feb 28 '18 at 11:42
  • 1
    Please check my edits, keep your up and if condition after that – Anup Yadav Feb 28 '18 at 11:51
  • I tried putting `ALLOWED_HOSTS=[*]`, I had to leave out the `INTERNAL_IPS` because it was giving a FilenotfoundError. It is still not showing up... – Chris Feb 28 '18 at 12:03
  • 4
    You should uncomment `INTERNAL_IPS`. If you're getting an error then you should include the full traceback of that in your question. If you don't set `INTERNAL_IPS`, then you need to [override the callback function](https://stackoverflow.com/a/10518040/113962), which makes the configuration more complicated, and could make the debug toolbar output available to other users which is insecure. – Alasdair Feb 28 '18 at 12:09
  • 1
    `INTERNAL_IPS` important to have, yes agree with @Alasdair – Anup Yadav Feb 28 '18 at 12:10
  • Okay. It gives this error when I put in the INTERNAL_IPS. `Exception Type: FileNotFoundError Exception Value: [WinError 3] The system cannot find the path specified: 'C:\\Users\\cbaldwin\\Documents\\Python\\project_8\\project_eight\\project_8\\static'` – Chris Feb 28 '18 at 12:14
  • 1
    No no, wait, actually toolbar worked for your project to me, but I'm using ubuntu, no windows. So I'm not sure, about this issue. But you fire that command and try chaning the setting for BASE_DIR. May be that should solve the issue – Anup Yadav Feb 28 '18 at 12:23
  • @Anup Yadav thank you for checking. So its possibly my windows laptop? I am using 'windows command prompt' if that would have anything to do with it? – Chris Feb 28 '18 at 12:28
  • May be try here adding this `STATIC_ROOT = BASE_DIR + '/static/'` after line of `STATICFILES_DIRS` – Anup Yadav Feb 28 '18 at 12:28
  • I put it below and it returned `ERRORS: ?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.` – Chris Feb 28 '18 at 12:32
  • 1
    You don't have a `static` directory in your project directory (the one containing `manage.py`), so you shouldn't have `os.path.join(BASE_DIR, 'static'),` in your `STATICFILES_DIRS` setting. You shouldn't have to set `STATIC_ROOT` at this stage - it's only needed when you want to collect your static files to serve them in production. – Alasdair Feb 28 '18 at 12:32
  • So I should replace the `BASE_DIR` with my 'minerals' folder? Like `os.path.join(minerals, 'static')`? – Chris Feb 28 '18 at 12:36
  • 1
    No, either fire collectstatic command, or remove `STATICFILES_DIRS` or `STATIC_ROOT` settings. – Anup Yadav Feb 28 '18 at 12:41
  • I removed the STATIC_ROOT but kept the STATICFILES_DIRS and it still gives FileNotFoundError – Chris Feb 28 '18 at 12:51
  • 1
    remove `STATICFILES_DIRS` as well – Anup Yadav Feb 28 '18 at 12:51
  • @Anup Yadav brilliant, that worked. Its now showing up. Thank you very much. – Chris Feb 28 '18 at 12:54
  • Great! Please accept the answer. What happened @Chris couldn't I help you? – Anup Yadav Feb 28 '18 at 12:55
  • Great! @Chris Thanks :) – Anup Yadav Feb 28 '18 at 12:59
  • 1
    Sorry, I don't use Stackoverflow much I don't know the rules, but you were the first to give the correct solution that I saw. You helped a lot thank you. – Chris Feb 28 '18 at 13:01
  • 1
    Thanks @Chris It's ok. No issues. I'm happy that I could help you. – Anup Yadav Feb 28 '18 at 13:03
2

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


JPG
  • 82,442
  • 19
  • 127
  • 206
  • It said ' name 'MIDDLEWARE_CLASSES' is not defined' so I changed 'MIDDLEWARE_CLASSES' to just 'MIDDLEWARE', and then it gave the error ' No module named 'debug_toolbar'. – Chris Feb 28 '18 at 11:24
  • I upgraded Django (I didn't realize I was using an old version) and it stopped saying that, but I tried your code again and it says `ModuleNotFoundError: No module named 'settings'` – Chris Feb 28 '18 at 11:49
  • 1
    @Chris Updated the answer – JPG Feb 28 '18 at 12:52
  • That worked great. Its now showing thank you for the help. – Chris Feb 28 '18 at 12:58
  • Sorry I suppose I can only give one accepted answer. I read the other correct answer first, but your answer was also spot on. I really appreciate the help. – Chris Feb 28 '18 at 13:02
1

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})()
rimvy
  • 11
  • 2
-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;
             }
A.M. Ducu
  • 892
  • 7
  • 19
Ananthu B
  • 1
  • 1