Using the Werkzeug debugger with Django
Some time ago, while researching about Flask we came across the Werkzeug project and we noticed one very special feature, the interactive debugger.
It’s been a while since we started using Docker containers on our development environments. One small consequence of this is that interactive consoles are not as easily accessible as before while running a whole application.
This is usually fine, except for some specifics, such as debugging Python code. Most debuggers are available only at the executing console.
We decided to try to enable the Werkzeug debugger for our Django projects. While on this, we discovered that this has been previously undertaken by the django-extensions project. Nevertheless, some problems arised while trying to use it:
- The debugging screen was not very friendly at the least towards frequently used development tools such as the Chrome console, cURL or Postman. This is twice as important if you are developing an API with DRF.
- It is a bit of overhead to install for every project, since we don’t regularly use it.
Given this two issues, and after careful inspection of the Werkzeug code, we decided to create a standalone management command rundbg
that provides solves both of this issues.
You can run it either for API development, as well as regular Django templates.
To use it, just install it with pip and switch from runserver
to rundbg
. If you are working on APIs add the --use-link
option.
If you place an assert False
in your code at some point, when hitting a View that executes this it will show you something like:

Following the link it will lead you to the interactive debugger.

More information, including installation and configuration guides available at the GitHub repo.
See related posts

Clean Code, Technical Debt, and Documentation in Python
Best practices for writing clean, orderly, well-structured Python code that respects the principles of readability, understandability, and respect for standards

From Python to Go or Rust?
Nowadays there are plenty of options for building backend systems. In this post we talk about the one we use in Octobot: Python/Django.