Clicking on Django debug toolbar tabs results in 404 Not Found error

Viewed 1747

I am trying to analyze and optimize my sql queries in my Django 1.10 project, and for this reason trying to setup Django Debug Toolbar. For now, I can see the toolbar appear on the left side of my browser, but when I click the tabs, I end up with 404 error.enter image description here

GET http://127.0.0.1:8000/debug/render_panel/?store_id=10d77fee31c2425aafb5a2cd7898111f&panel_id=SQLPanel 404 (Not Found)

My URLConf file:

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

urlpatterns += (
    url(r'', include('my_project_urls.urls')),
    # ...
)

settings.py (only relevant content):

ROOT_URLCONF = 'android_blend.urls'
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_URL = '/static/'

if DEBUG:
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
#STATIC_ROOT = [os.path.join(BASE_DIR,"static-only")]
    MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","media")
#MEDIA_ROOT = [os.path.join(BASE_DIR,"media")]
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR,"static"),
    )

def show_toolbar(request):
    if not request.is_ajax() and request.user and request.user.id == 4:
        return True
    return False

DEBUG_TOOLBAR_CONFIG = {'SHOW_TOOLBAR_CALLBACK': 'android_blend.settings.show_toolbar'}

I blame the error on an erroneous settings regarding static files. In the cmd, when I navigate to the project root folder and run python manage.py collectstatic, I see a folder named static appear on my Desktop, instead of project root. I manually copied the static-only folder which was in the newly created static folder into the static folder of my project root, but again no success. Could anyone help me with finding the solution ? Any hint would be appreciated.

3 Answers

From a recent django-debug-toolbar version (1.9.1), I've downgraded to an older one (1.6) and I'm no longer getting a 404.

For me, I put the __debug__ URL above the static and media routes and then it works.

if settings.DEBUG:
    urlpatterns.append(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)
Related