Django: How to Quickly Debug w/o setting DEBUG=True

Timur Bakibayev, Ph.D.
Django Unleashed
Published in
2 min readOct 20, 2023

--

A short trick how to debug your Django app

Say, you have a Django app running on the server, and there are a lot of users currently using it.

Now, you have a bug, and turning DEBUG to True is not an option. You still want to see your logs and an error. And no, you cannot reproduce this bug locally, because “it works on your machine”.

First, choose a free port number and add a rule to firewall. Say, we have chosen port 8002:

sudo ufw allow 8002/tcp

Now, simply run your app with runserver on port 8002:

python manage.py runserver 0.0.0.0:8002

You will see a normal console:

(venv) root@ubuntu-s-2vcpu-4gb-fra1-01:/var/www/yourapp/yourapp# python manage.py runserver 0.0.0.0:8002
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 20, 2023 - 11:01:45
Django version 3.0.5, using settings 'yourapp.settings'
Starting development server at http://0.0.0.0:8002/
Quit the server with CONTROL-C.

Now, in your browser, add :8002 into your url.

So, if the bug is at www.yourapp.com/about simply type www.yourapp.com:8002/about . Look at your console, you will see all your messages.

We all debug with prints, right? But how do we debug the Django Templates?

--

--