2

enter image description here I connected like in instruction, when run server all is ok, but when open site I see the ERROR:

'djdt' is not a registered namespace

What should I do? With what connect problem?

setting.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1']
INTERNAL_IPS = ['127.0.0.1',]

INSTALLED_APPS =  [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'news',
    'django_summernote',
    'debug_toolbar',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),]
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

urls.py

app_name = 'news'
urlpatterns = [
     ...
]
if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [path('__debug__/', include(debug_toolbar.urls)),]
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I don't know why there is ERROR. I did all what write in instruction. May be problem with statics root?

Salvatore
  • 10,815
  • 4
  • 31
  • 69
Alexxx
  • 49
  • 3

1 Answers1

3

The djdt docs on installation show that you need to include the '__debug__/' path before the rest of your url patterns. You should change your code to something like:

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Greg Kaleka
  • 1,942
  • 1
  • 15
  • 32
  • This is no longer the case, and the documentation shows the debug toolbar URLs being added at the *end* of `urlpatterns`. – Phil Gyford May 11 '22 at 16:06