Remix.run Logo
Izkata 6 hours ago

> * settings.py actually conflates project config (Django apps, middleware, etc) and instance/environment config (Database access, storages, email, auth...); I hardcode the project config (since that doesn't change between environemnts) and use python-dotenv to pull settings from environment / .env; I document all such configurable vars in .env.example, and the defaults are sane for local/dev setup (such as DEBUG=true, SQLIte database, ALLOWED_HOSTS=*, and a randomly-generated SECRET_KEY); oh and I use dj-database-url to use DATABASE_URL (defaults to sqlite:///sqlite.db)

There is a convention to create "foo_settings.py" for different environments next to "settings.py" and start it with "from .settings import *"

You'll still want something else for secrets, but this works well for everything else, including sane defaults with overrides (like DEBUG=False in the base and True in only the appropriate ones).

seabrookmx 2 minutes ago | parent [-]

IMO this is an antipattern because having a python file for each environment means you have bespoke code for each environment that is difficult to test and easily diverges.

If you use OP's way (I do something similar using pydantic-settings) the only thing that changes is your environment vars, which is much easier to reason about.