djangohtmxdjango-debug-toolbar

Why is django debug toolbar causing a 'ValueError at ... Another profiling tool is already active' error when Htmx ajax fires?


I had django-debug-toolbar working fine in my application until I added htmx. Now I'm getting Another profiling tool is already active error. enter image description here

The page loads then htmx fires on load to add more content. Below is the offending line

<div id="group-list" hx-get="{% url "my-rental-property-groups" rental_property.id %}" hx-trigger="load"></div>

If I change the change the hx-trigger attribute to hx-trigger="load delay:5s" to add a delay of 5 seconds, then the error goes away but that's not a solution. A smaller delay still throws the same error.

If I add "SHOW_TOOLBAR_CALLBACK": lambda request: False, to DEBUG_TOOLBAR_CONFIG section below, the page renders fine but the Debug Toolbar is disabled

DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK": lambda request: False, #THIS LINE DISABLES DEBUG TOOLBAR WIHOUT SETTING DEBUG TO FALSE    
    "SHOW_TEMPLATE_CONTEXT": True,
    "ROOT_TAG_EXTRA_ATTRS": "hx-preserve", # https://django-debug-toolbar.readthedocs.io/en/latest/tips.html#working-with-htmx-and-turbo
}

I'm looking for a solution that will allow me to keep Htmx and Django Debug Toolbar working together.


Solution

  • TL;DR Uncheck the Profiling checkbox in Django Debug Toolbar panel

    AARGH!!! It turned out to be something stupid. I had accidentally clicked the Profiling checkbox at the bottom of the Django Debug Toolbar panel (See screenshot below). I unchecked this and everything is working fine. Obviously you have to navigate to a page that's not throwing the error to access this setting. With profiling unchecked, now I don't need the SHOW_TOOLBAR_CALLBACK setting in the config

    enter image description here