Django Debug Toolbar not showing up

My Django Debug Toolbar is not showing up. I hope you can help:
https://github.com/qvisty/DjangoPro40

My .env contains this (and more, not shown):

DJANGO_DEBUG=True

I’m trying to follow Django for Professionals by Will Vincent, but I cant get this part to work… :frowning:
Great book - I can recommend it very much

The docs have some tips. Give those a go and let us know what the results are.

I tried those, but in case I missed something I posted here.

Your repo is currently private. That will need to be made public if you want us to review the code. Otherwise, you can let us know what you’ve tried. Share your installed apps, middleware, toolbar settings, and whether the toolbar is being injected into the HTML, but not shown or if it’s not being injected at all. Other questions: are you using docker, are you using channels, did the toolbar show up when you browse to the admin?

Private. Sorry :upside_down_face:.
Should be public now

Wow. I will answer those tomorrow when on pc. (bedtime in my pytz😉)

Another question, are you running this locally?

Yes. I tried manually entering the adress in internal_ips

In settings.py I tried the following:

Trying all different options I could think of for
INTERNAL_IPS = [127.0.0.1]
INTERNAL_IPS = [‘127.0.0.1’]
INTERNAL_IPS = [127.0.0.1,]
INTERNAL_IPS = [‘127.0.0.1’,]

Moving “debug_toolbar.middleware.DebugToolbarMiddleware”, up and down in the MIDDLEWARE.

Change debug = True instead of DEBUG = env.bool(“DJANGO_DEBUG”)

I made sure it is in installed apps.

This is my allowed hosts setting: ALLOWED_HOSTS = [".herokuapp.com", “localhost”, “127.0.0.1”]
Not sure if that makes a difference.

I restarted the server.

No more ideas.

1 Like

Answers to these question?

If you’re using “localhost” as the address in your browser address bar, you might want to add it to INTERNAL_IPS.

Also, you’re showing an external name in ALLOWED_HOSTS - are you running this in heroku? If so, you need to add your public-facing IP address to INTERNAL_IPS - and, depending upon your ISP and heroku, it might be an IPv6 address as well. (The INTERNAL_IPS list is checking for the REMOTE_ADDR header in the request - it’s verifying that the browser making the request is in that list. Check your server log to see what is showing as the IP address making the requests.)

Thank you guys. I will try to answer all your specific questions when I am able tofind pc time. :grin:
Ill be back…

Just to recap. I am really wondering why it does not work as I am following Will’s book Django for Professionals, but I am skipping the Docker and testing part (this time round). Maybe this will affect it.

installed apps:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.sites",
    # Third-party
    "crispy_forms",
    "crispy_bootstrap5",
    "allauth",
    "allauth.account",
    "debug_toolbar",
    # Local
    "accounts.apps.AccountsConfig",
    "pages.apps.PagesConfig",
    "books.apps.BooksConfig",
]```
middleware:

MIDDLEWARE = [
“django.middleware.security.SecurityMiddleware”,
“django.contrib.sessions.middleware.SessionMiddleware”,
“django.middleware.common.CommonMiddleware”,
“django.middleware.csrf.CsrfViewMiddleware”,
“django.contrib.auth.middleware.AuthenticationMiddleware”,
“debug_toolbar.middleware.DebugToolbarMiddleware”,
“django.contrib.messages.middleware.MessageMiddleware”,
“django.middleware.clickjacking.XFrameOptionsMiddleware”,
]```
toolbar settings:

# django-debug-toolbar
import mimetypes

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

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

docker and channels:
both no

show up in the admin:
no

I am using this code from Will’s book:

# django-debug-toolbar
import mimetypes

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

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

No not yet. The heroku-code is because one of the follow chapters is “Deploy”

That code appears to also be what is documented here: Installation — Django Debug Toolbar 4.2.0 documentation, which applies to a Docker-based installation. Since you’re not using Docker, I don’t think it would apply.

And again - this is asking for what you are entering in your address bar in your browser to go to your site.

When testing your site, do you use:

  • http://127.0.0.1/
  • http://localhost/
  • http://something-else/ (non-local address)

What you want to look at is your server logs - specifically, what is being received as the REMOTE_ADDR header in the http request. The easiest thing to do to identify this is to throw a print statement to print that header in a view and see what you’re getting.
Whatever you’re getting is what needs to be in your INTERNAL_IPS list.

This option, yes. :slight_smile:

I dont think I have any server logs? I tried looking in the developer console in the browser but could not find the remote_adr…

Then yes, your INTERNAL_IPS should include an entry for ‘127.0.0.1’. (It’s a string, not a number, so must be enclosed in quotes.)

I saw where you said that you had tried this before, so I’m now willing to rule this out as the likely cause of the issue you’re facing, pending verification of the REMOTE_ADDR header. (And based on your logging comment, a print statement in a view may be the easiest way to verify it. You could also look at the network tab in your browser’s developer tools to see the request.)

From the docs at Installation — Django Debug Toolbar 4.2.0 documentation, you might want to move the middleware to the top of the list.

Actually, I was just reminded you posted a link to the entire project - I’m going to pull a copy to see what happens here…

Well, I hate to say it, but your project works for me exactly as posted in git - making three trivial changes. (Changed the database to match a test database I created for this, set DEBUG=True rather than an environment variable, and set INTERNAL_IPS = ['127.0.0.1']), and this is what I get:

2 Likes

I’ll try this and see where it breaks when I try to “get it back”. :slight_smile:

I changed my database to original django sqlite code.
I changed internal_ip as you demonstrated above.
I move debug_toolbar middleware to the top of the list.

… Still not showing up.
I am giving up on this and move on in the book. I will give this an other try some time later.
Thank you all for helping.

Hi,

Have you checked once in the Developer Console of your browser? In my case I had a MIME Type error on Windows. To be exact:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/plain”. Strict MIME type checking is enforced for module scripts per HTML spec.

To solve this, I had add the following lines of code to my project settings.py.

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

Hope this solves your issue.

Kind regards
Pavan Kumar Akula.