Skip to content

django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lemaadi opened this issue Sep 21, 2020 · 3 comments · Fixed by #1349
Closed

django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace #1332

lemaadi opened this issue Sep 21, 2020 · 3 comments · Fixed by #1349

Comments

@lemaadi
Copy link

lemaadi commented Sep 21, 2020

Hi there,

I'm trying to configure django-debug-toolbar. As of now i did the following :

settings.py

DEBUG=True
if DEBUG:
INSTALLED_APPS += [ "debug_toolbar", ]

MIDDLEWARE += [
    "debug_toolbar.middleware.DebugToolbarMiddleware",
]

INTERNAL_IPS = [
    "127.0.0.1",
]

DEBUG_TOOLBAR_PANELS = [
    "debug_toolbar.panels.versions.VersionsPanel",
    "debug_toolbar.panels.timer.TimerPanel",
    "debug_toolbar.panels.settings.SettingsPanel",
    "debug_toolbar.panels.headers.HeadersPanel",
    "debug_toolbar.panels.request.RequestPanel",
    "debug_toolbar.panels.sql.SQLPanel",
    "debug_toolbar.panels.staticfiles.StaticFilesPanel",
    "debug_toolbar.panels.templates.TemplatesPanel",
    "debug_toolbar.panels.cache.CachePanel",
    "debug_toolbar.panels.signals.SignalsPanel",
    "debug_toolbar.panels.logging.LoggingPanel",
    "debug_toolbar.panels.redirects.RedirectsPanel",
    "debug_toolbar.panels.profiling.ProfilingPanel",
]

DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG,
    "RESULTS_CACHE_SIZE": 3,
    "SHOW_COLLAPSED": True,
    "SQL_WARNING_THRESHOLD": 100,
}

urls.py

if settings.DEBUG:

import debug_toolbar

urlpatterns = [path("__debug__/", include(debug_toolbar.urls)),] + urlpatterns

The toolbar is working correctly, but when i run pytest tests/ or docker-compose run --rm app pytest tests/ i get this error :

django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace for some tests suite.

So, what did i missed ??
Thank's in advance

@tim-schilling
Copy link
Member

You should only include the debug toolbar's urls when settings.DEBUG == True. Then your tests should run with DEBUG set to False.

@lemaadi
Copy link
Author

lemaadi commented Sep 21, 2020

Thank you @tim-schilling for your response
I already tested this option and it works : setting DEBUG=False means tests pass but debug toolbar does not show in the browser.
My goal is to include debug toolbar and run tests with DEBUG=True
Is this possible ?

@tim-schilling
Copy link
Member

You could configure the debug toolbar with an environment variable, then run runserver with it set, such as TOOLBAR="True" python manage.py runserver

Or you can create a separate local settings file and use that in the call to runserver via python manage.py runserver --settings=config.settings.local where config.settings.local is the python path to your local settings file.

If you have it available, there's a chapter on Settings and Requirements files in Two Scoops of Django that goes into detail about this.

matthiask pushed a commit that referenced this issue Oct 1, 2020
Remove the "if settings.DEBUG" guard. This guard is not necessary and
leads to several edge cases in local development setups.

This is not necessary as all views are guarded by the
require_show_toolbar decorator which uses the SHOW_TOOLBAR_CALLBACK
setting. This setting is already capable of enabling/disabling across
the application when DEBUG is False. By default, when DEBUG is False,
these views return a 404 response.

By having the URLs always available, the MIDDLEWARE setting also doesn't
need special handling when DEBUG is False, simplifing the overall
configuration. An application should be able to reliably reverse URLs
regardless of the status of DEBUG.

Fixes #1035
Fixes #1043
Fixes #1332
adRn-s added a commit to maxplanck-ie/parkour2 that referenced this issue Jul 27, 2022
adRn-s added a commit to maxplanck-ie/parkour2 that referenced this issue Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants