0

How can i set up django debug toolbar when using django static files and media files

Below is my configuration in urls.py

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

I am not sure whether the line with 'elif' is the right way to do it. (The web app crashes when i try to launch it in dev)

Curtis Banks
  • 342
  • 4
  • 20

1 Answers1

1

Your code will never go to elif block if first condition evaluates to Ture and you are never going to get toolbar in DEBUG mode. Accroding to docs you should do something like this.

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        path('__debug__/', include(debug_toolbar.urls)),

        # For django versions before 2.0:
        # url(r'^__debug__/', include(debug_toolbar.urls)),

    ] + urlpatterns

So your final code should be (As you have additional piece)

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls))
    ]
Nafees Anwar
  • 6,324
  • 2
  • 23
  • 42