Feature request: clear console on reload

Hello !
I’d like to add a feature to Django to automatically clear the console when hot-reloading.
This could be implemented as a flag, for example by doing python manage.py runserver --clear-on-reload

I’m ready to submit a PR for this myself, at some point in the future.

What do you think about this feature ?

I’m not sure. For the cases where I get lost in my console output, I’ll add a few newlines and that usually does the trick for me. Otherwise, I don’t really bother with clearing my scrollback.

I wonder if this would be more acceptable for django-extensions’ runserver_plus? Or maybe you can find a way for people to experiment with this so they can be convinced this feature is a major benefit?

Just to be clear, “clearing the console" won’t mean actually removing the scrollback. It just means restarting rendering from the top of the screen. The way to achieve this is print("\x1bc"). Scroll

Personally, I’m not really a fan of the proposal.

First, I like the way the output stays pinned to the bottom of the window. Reloading pushing that to the top seems unnecessary, as it will require scanning back up the window to find the latest requests.

Second, it would presumably mean clearing after the INFO <filename> changed, reloading. log message, making it a little bit harder to debug issues with unexpected reloads.

But thanks for the suggestion @itrooz, it’s always good to see developer experience improvements being thought about. I think some colourization would be an easier way to improve the development server output.

Yeah I meant that sorry

The problem I encountered with this was while debugging an endpoint, Django was printing a long stacktrace. And I wanted to read the latest stacktrace, and not the one before by mistake. So I ended up disabling auto-reload, and just clear-ing the console and re-running Django every time I modified my code, which was annoying

Alternatively, I suppose I could run Django through something like nodemon for auto-restarting the process (something like npx nodemon --signal SIGKILL --ext py --exec "clear && python manage.py runserver") but I’d love an easier option to exist.

I think showing the “reloading” message after clearing the console should not be a problem

I never heard about django-extensions before today. Unfortunately, I don’t want to add a dependency on my code (you have to add the django_extensions to your INSTALLED_APPS right ?) just for a QoL improvement in a dev environment

So creating and keeping up-to-date a fork of Django and seeing if people want to use it, for an added clear command ?

Welcome @iTrooz !

I’m in the habit of going to the console window and holding down the return key to give me 10ish blank lines between tests.

Personally, I would find it extremely difficult to give up at this point. It’s an essential part of my development environment. (Yes, I know not everyone is a fan of it, but I am. And, depending upon what commands you use, it could also be a vital part of your production environment as well.)
But, in the minimal case, I don’t really consider it much different than DjangoDebugToolbar or any other dev-time usage package. It’s easily removed for production deployments.

Doesn’t need to be a full Django fork. It could be a third-party package of a custom command, much in the same realm as django-extensions.

I agree that this helps, but I’m still anxious if I don’t clear the console

So, id I understand correctly, there is a lower barrier for merging on django-extensions. I will try my luck there then, thanks !