In this article, we are going to make a Django profiling. It will show a great deal of information like the total number of GET requests, database queries and many other reports for your website on a URL endpoint. It is great in production because you need to keep a check on many things when your site is in production.
It is a great resource if you have to deploy a real-world project.
Example
First of all, create a project and an app. Do some basic settings and set up the urls.
Now, install the djnago-silk package −
pip install django-silk
In settings.py, add the following lines −
MIDDLEWARE = [ ... 'silk.middleware.SilkyMiddleware', ... ] INSTALLED_APPS = [ ... 'silk' ]
We simply added it as app and a middleware and module as an app.
In project's url.py −
urlpatterns += [path('silk/', include('silk.urls', namespace='silk'))]
Here we defined the endpoint where we will see profiling.
Now run these commands −
python manage.py makemigrations python manage.py migrate
These commands are for creating silk migrations and to migrate them.
With that, everything is set and you can proceed to check the output.
Output
Go to https://127.0.0.1:8000/silk/