jazzband / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
8.02k stars 1.04k forks source link

Using the toolbar with Replit #1941

Closed TimGilchristCA closed 1 week ago

TimGilchristCA commented 1 month ago

Hi, I'm using the Replit Web Development Environment (I'm looking to use this with students to avoid them needing a desktop to setup a development environment) to complete the Django tutorial and have successfully got to the bit where it suggests installing the debug toolbar. I've followed the instructions and it installs ok but I can't see the toolbar. I'm guessing it is something to do with the INTERNAL_IPS setting as I'm not running on a local machine so presumably the IP address 127.0.0.1 may not be correct. Any idea how I can get round this?

tim-schilling commented 1 month ago

@TimGilchristCA if you followed the Django tutorial to it's exact specifications, the responses don't include the <body></body> tags and the toolbar will not inject itself into it.

From the django tutorial:

Note To make the tutorial shorter, all template examples use incomplete HTML. In your own projects you should use complete HTML documents.

From the Debug Toolbar Docs, "The toolbar isn't displayed!":

It will also only display if the MIME type of the response is either text/html or application/xhtml+xml and contains a closing tag.

Can you give that a check? You can also try overriding the SHOW_TOOLBAR_CALLBACK configuration option

TimGilchristCA commented 1 month ago

Hi Tim thanks for getting back so quickly. I have been using complete HTML docs so I don't think that is the issue. I'm very new to this so I'm afraid I don't actually understand how to check "It will also only display if the MIME type of the response is either text/html or application/xhtml+xml and contains a closing tag." Similarly how do I override the SHOW_TOOLBAR_CALLBACK configuration option. Sorry to be so helpless! From my understanding of what is going on I think it is something to do with the 127.0.0.1 because if I'm using a Web based environment like Replit what does "local server" even mean in that context?

tim-schilling commented 1 month ago

That's likely the next thing to check. If you're running the toolbar in a remote environment (not recommended by the way since it exposes sensitive information), you'd need to add your computer's IP address to the server's INTERNAL_IPS setting. Since that can change, it's best to do it via an environment variable. This will basically tell the server, "hey, this person is known and can use the toolbar".

Similarly how do I override the SHOW_TOOLBAR_CALLBACK configuration option.

The end of the configuration docs has an example for you.

# This example is unlikely to be appropriate for your project.
DEBUG_TOOLBAR_CONFIG = {
    # Toolbar options
    'RESULTS_CACHE_SIZE': 3,
    'SHOW_COLLAPSED': True,
    # Panel options
    'SQL_WARNING_THRESHOLD': 100,   # milliseconds
}
tim-schilling commented 1 month ago

If you're asking how to specifically customize SHOW_TOOLBAR_CALLBACK, you'd need to write a function that takes a request and follows the callback(request) signature as mentioned in the docs. You can look at how the toolbar manages the default callback here: https://github.com/jazzband/django-debug-toolbar/blob/main/debug_toolbar/middleware.py#L19

tim-schilling commented 1 week ago

Closing as stale.