While this is generally true, I wouldn’t call it an absolute. There are a number of niche or limited circumstances where this could be considered perfectly acceptable. It’s important to understand why this could be a problem, and evaluate the risks accordingly.
In general, you would find that people tend to keep a set of settings in common for all environments, with a way of configuring those items being different.
The reason you won’t find much (if anything) about this in the official docs is that there are multiple ways of handling it, and they’re generally all good. There are at least three different libraries that I can think of to allow you to use environment variables. You can also store the settings in files using different mechanisms for using those settings. And, depending upon the setting, people might use more than one of these in a single project.
The point is, it’s flexible. Do it however you feel comfortable with managing it, and that satifies whatever external policies or limitations you may be required to comply with. (For example, I once worked with someone in an environment where they could not do a deployment to production - a different team was responsible for that. Additionally, that team did not have access to the production databases - those credentials had to be supplied by yet another team. Now, that was in my “pre-Django” days, so I never saw Django deployed in that environment - but I understand what would be necessary.)
There’ve been a number of discussions in the forum about this topic to one degree or another. For example, see Settings refactor and the various discussions it references. So it’s not like there isn’t some interest in identifying a “standard” or “canonical” solution - but we’re not there yet.
In my case, I don’t typically have database credentials in the settings at all. Most of the time, I connect using a unix domain socket with peer authentication. (See PostgreSQL: Documentation: 18: 20.9. Peer Authentication)
Or, if I need to do something else, I might use a .pgpass file. (See PostgreSQL: Documentation: 18: 32.16. The Password File)
Either way, the database credentials are managed completely outside the context of the application itself.
I am not consistent with how I manage other configuration items. I have tried a number of different methods through the years, some with more success than others. Since I’m now just coding for my own pleasure, things are a lot simpler for me. My current personal favorite includes adding code to my settings.py file to test the DEBUG setting, and changing behavior based on that.
(Side note: I actually got this idea from django-debug-toolbar. In older releases, you would conditionally add the urls in an if settings.DEBUG statement. I figured if it was good enough for them, it’s good enough for me - and I like the idea of having all settings in one file.)
You’ll find most of them at Deployment checklist | Django documentation | Django