SoFunction
Updated on 2024-11-17

Configuration and use of django-debug-toolbar in Django Web Development

preamble

django, web development, with django-debug-toolbar to debug the requested interface, is undoubtedly perfect. Maybe I, shallow knowledge, only to say perfect to the extreme, the gods, table spray, fist.

django_debug_toolbar is a third-party toolkit for django that extends django with debugging capabilities.

This includes viewing executed sql statements, db query counts, requests, headers, debugging overviews, and more.

The django-debug-toolbar is configured as follows

Step one:

pip install django-debug-toolbar

Once the installation is complete. It's time to move on to the next configuration.

Step two:

Open the project and locate the file. Find:

INSTALLED_APPS - variable

Take the following code and add it in.

'debug_toolbar'

Keep adding: Find the place where the middleware is placed and add the following code to it.

'debug_toolbar.',

# Be sure to add the end “ , ” comma (punct.)

Once the middleware is added, it's time to add the django-debug-toolbar middleware.

DEBUG_TOOLBAR_PANELS = [
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
 'debug_toolbar.',
]

Add Access IP

INTERNAL_IPS = ('127.0.0.1',)

Modify django-debug-toolbar to change the source.

python3 --> Lib --->site-packages --->

Open the settings file and look for the (CONFIG_DEFAULTS) variable, change the key: value of JQUERY_URL.

///jquery/2.1.4/

Once you've configured it, it's ok, just runserver it.

After running, open the browser to enter the IP, you can see the effect of it, but also may be in the middle of maybe someone will install error. Sorry, I installed it in one step.

After the installation error, you will be asked to baidu yourself.

Page effects:

After opening the URL the page will appear in the above picture, go here, that is, the installation has been completed.

Simple use of dajngo-debug-toolbar

Each time an interface is requested, the right-hand column becomes.

As pictured:

I clicked on sql, which is how long it takes to go to the database to check the data, and when I clicked on sql, I saw the data on the right side, and Time is in milliseconds, and the following is how long it takes to request the database.

Optimize where time is slow.

Follow the table where the red box is, tap on it, and you will see the block Connection: default.

The meaning of this piece is that the code there is delayed, or repeating the loop, will be prompted, when you request the interface does not have this message anymore, it means, you have optimized successfully.

summarize

Here this tutorial is finished, if you write the wrong place, please point out, or there are other good use of things, also please leave a message to point out one or two. Thank you for your time.

I hope that the content of this article on your learning or work has a certain reference learning value, if there are questions you can leave a message to exchange, thank you for my support.