Django: hide the development server warning

From Django 5.2 (April 2025), the runserver management command outputs a warning:
$ ./manage.py runserver
...
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
The warning uses bold, yellow text for emphasis.
Here’s the relevant release note:
A new warning is displayed when runningrunserver, indicating that it is unsuitable for production. This warning can be suppressed by setting theDJANGO_RUNSERVER_HIDE_WARNINGenvironment variable to"true".
I think the warning is somewhat useful for new users, who do sometimes skip the deployment checklist that states that runserver is not designed for production use. That said, the warning is rather annoying for the majority of users who have correctly set up a production server. I also fear it will lead to warning fatigue, normalizing that runserver outputs lots of warning text, making it easier to skip over other, more pressing messages that may be logged.
If you’ve set up your production environment to use a secure server, like gunicorn, then you probably want to hide this warning. As the release note states, you can do this by setting the environment variable DJANGO_RUNSERVER_HIDE_WARNING to "true".
While you can manage environment variables in a bunch of different ways, I think the simplest method here is to set it at the top of your settings file:
import os
# Hide development server warning
# https://docs.djangoproject.com/en/stable/ref/django-admin/#envvar-DJANGO_RUNSERVER_HIDE_WARNING
os.environ["DJANGO_RUNSERVER_HIDE_WARNING"] = "true"
(I would rather this warning was configured with a setting, or it came through the system check framework, but that’s a change for a future Django release, at most.)
With those lines in place, runserver will be a little bit more peaceful:
$ ./manage.py runserver
...
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸
One summary email a week, no spam, I pinky promise.
Related posts:
Tags: django