Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After adding django-debug to App, getting "'djdt' is not a registered namespace"

My question is about setting up to use django-debug. I'm getting the above error after installing the toolbar and panel, and enabling these in my app. I've seen many suggestions for this or a closely related issue, and nothing I've tried has helped.

The specific error, during template rendering of /usr/lib/python3.6/site-packages/debug_toolbar/templates/debug_toolbar/base.html, is from:

16       data-render-panel-url="{% url 'djdt:render_panel' %}"

My relevant settings.py entries:

DEBUG = True
INSTALLED_APPS = [
    'debug_toolbar',
    'debug_panel',
    ...
]
MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'debug_panel.middleware.DebugPanelMiddleware',
    ...
]
INTERNAL_IPS = ['127.0.0.1',]

Appended to my urls.py:

if settings.DEBUG:
    try:
        import debug_toolbar
        urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))]
    except ImportError:
        pass

What I've tried:

  • changing the order of these Middleware entries in settings.py (first, middle and last)
  • adding a namespace attribute to my urlpatterns entry

Thanks for any further suggestions.

like image 899
CodeMantle Avatar asked Aug 23 '18 12:08

CodeMantle


3 Answers

You need to manually add 'djdt' routes to the end of urls.py (if you use 'namespace' in your apps, add below codes to 'urls.py' in your project):

if settings.DEBUG:
    import debug_toolbar

    urlpatterns += [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ]
like image 97
Milad Hatami Avatar answered Nov 05 '22 16:11

Milad Hatami


if this problem occurs when we set DEBUG to False then simply removing debugtoolbar middleware from the list fixed the problem.

  • settings.py
MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

if DEBUG is False:
    del MIDDLEWARE[0]
  • urls.py
from django.conf import settings
from django.conf.urls import include

...

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
like image 7
Arbazz Hussain Avatar answered Nov 05 '22 18:11

Arbazz Hussain


The error is due to we declare its middle but the module is not import in case DEBUG = FALSE. So, just check to add its middle in case DEDEUG is set TRUE

settings.py

MIDDLEWARE = [
    ...
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
....
]

if DEBUG:
    
    MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE

urls.py

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
like image 1
Dat TT Avatar answered Nov 05 '22 18:11

Dat TT