Home > OS >  Django Debug Toolbar causes 404 error in DEBUG mode
Django Debug Toolbar causes 404 error in DEBUG mode

Time:12-02

After installing Django Debug Toolbar and adding all setting, I'm getting 404 error. I did command collectstatic, but that did not help. Here is my files:

settings.py

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    ....
    INSTALLED_APPS = [
    ...
    'debug_toolbar',
    ...
    ]
    MIDDLEWARE = [
    ...
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    ]
    ...
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'spare_part/static')
    ]
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    MEDIA_URL = '/media/'

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    INTERNAL_IPS = ["127.0.0.1", ]

urls.py

    urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('mileage.urls')),
    ]

    if settings.DEBUG:
        import debug_toolbar

        urlpatterns = [
            path('__debug__/', include(debug_toolbar.urls)),
        ]
        urlpatterns  = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
        urlpatterns  = static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

What to do?

error

CodePudding user response:

Just found the solution:

in urls.py might to be "urlpatterns ="

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

CodePudding user response:

change url.py to :

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('mileage.urls')),
]

if settings.DEBUG:
    import debug_toolbar

    urlpatterns  = [
        path('__debug__/', include(debug_toolbar.urls)),
    ]
    urlpatterns  = static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)
    urlpatterns  = static(settings.STATIC_URL, 
    document_root=settings.STATIC_ROOT
  • Related