Using Django-Debug-Toolbar

Django-Debug-Toolbar Mainpage

My System Configuration

Django Version: 2.0.4 Django-Debug-Toolbar Version: 1.9.1

install django-debug-toolbar

Add following to the end of file settings.py of the project.

if settings.DEBUG:
	INTERNAL_IPS = [
		# to work in development
		'127.0.0.1',
	]

	MIDDLEWARE += [
		'debug_toolbar.middleware.DebugToolbarMiddleware',
	]

	INSTALLED_APPS += [
		'debug_toolbar',
	]

Please ensure that in settings.py

DEBUG = True

Django-Debug-Toolbar only works with the debug mode.

Add following to the end of file urls.py of the project.

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

FAQ

'set' object is not reversible

When running manage.py to runserver, the error occured.

Q:

debug_toolbar/base.html, error at line 16

'set' object is not reversible

A: In the urls.py of app:

# Error
urlpatterns = {
	path('', views.index, name='index'),
}

# Right, replace {} by []
urlpatterns = [
	path('', views.index, name='index'),
]

Query spend 30s by 20w rows of data in mysql

Q:

In Django model, I set the ordering with 'create_time'. So everytime I query the table it will order the result in 'create_time' which spent much time.

A: Create index on the ordering column.