From e9381e337fd5c7b2733c95fe6c00094e0bbdecb3 Mon Sep 17 00:00:00 2001 From: Scott Burns <13770321+scott-8@users.noreply.github.com> Date: Fri, 10 Apr 2026 15:56:41 -0400 Subject: [PATCH] Don't check for URLs if `ROOT_URLCONF` isn't defined --- debug_toolbar/apps.py | 15 ++++++++++----- docs/changes.rst | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/apps.py b/debug_toolbar/apps.py index 776c6a810..324ea490e 100644 --- a/debug_toolbar/apps.py +++ b/debug_toolbar/apps.py @@ -249,12 +249,17 @@ def debug_toolbar_installed_when_running_tests_check(app_configs, **kwargs): dt_settings.get_config()["SHOW_TOOLBAR_CALLBACK"] != CONFIG_DEFAULTS["SHOW_TOOLBAR_CALLBACK"] ) - try: - # Check if the toolbar's urls are installed - reverse(f"{APP_NAME}:render_panel") - toolbar_urls_installed = True - except NoReverseMatch: + + if not hasattr(settings, "ROOT_URLCONF"): + # reverse will raise AttributeError if ROOT_URLCONF is not defined toolbar_urls_installed = False + else: + try: + # Check if the toolbar's urls are installed + reverse(f"{APP_NAME}:render_panel") + toolbar_urls_installed = True + except NoReverseMatch: + toolbar_urls_installed = False # If the user is using the default SHOW_TOOLBAR_CALLBACK, # then the middleware will respect the change to settings.DEBUG. diff --git a/docs/changes.rst b/docs/changes.rst index 7af2dd769..e5726591e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -3,6 +3,7 @@ Change log Pending ------- +* Prevent check from failing when ``ROOT_URLCONF`` is not defined. 6.3.0 (2026-04-01) ------------------