I added a new tool to my toolbox this week, Silk. Which is defined like this in their documentation.
Silk is a live profiling and inspection tool for the Django framework.
As a maintainer of a Django project this is a great tool in many ways.
- Works seamless with Django REST framework
- Can give you a good overview on how your endpoints are used
- See details about HTTP requests/responses
- SQL query details
- And more...
The tool is added as a regular middleware for a typical Django project, so it's pretty straightforward to add it.
First we need to install the
python -m pip install django-silk
After the package is installed we will need to update our list of middlewares in the
setting.py file. The placement in the list can matter, read more about it here.
MIDDLEWARE = [ ... "silk.middleware.SilkyMiddleware", ...
We also need to add silk as an app.
INSTALLED_APPS = ( ... "silk", ... )
To be able to use the front-end for Silk we will need to add its path to the
urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))]
Since the tool is using the database to store its data we will also need to do a database migration.
python manage.py migrate # And collect static files from each applications python manage.py collectstatic # Start the server python manage.py runserver
Now you can start to explore all the nice things with Silk. The Silk UI is located at http://localhost:8000/silk.
If you want to do some profiling you will need some more configuration, which also is easy to get started with.
This is really a must have tool if you are doing anything with Django.
Give it a try!