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.
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.
I don't know if you already found it but there has been a breaking change which was "announced" here:
https://github.com/jazzband/django-debug-toolbar/issues/954
and documented here:
https://github.com/jazzband/django-debug-toolbar/pull/961/commits/22c22d719e856045e76b399d4e4ab5dc5e3fc040
For versions < 1.8, the callback should also return False for AJAX requests. Since version 1.8, AJAX requests are checked in the middleware, not the callback. This allows reusing the callback to verify access to panel views requested via AJAX.
So your code should be fine like this:
def show_toolbar(request):
if request.user and request.user.id == 4:
return True
return False
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With