Managing Django settings across local development and production environments can be a challenge. Some settings, such as constants, can be shared between both while others, like file paths, require variation.
The recommended approach, as outlined in "Two Scoops of Django," is to employ version control and store settings in a dedicated directory within your project:
project/ app1/ app2/ project/ __init__.py settings/ __init__.py base.py local.py production.py manage.py
Common Settings in base.py
settings/base.py houses settings shared across both environments, such as MEDIA_ROOT and ADMIN.
Site-Specific Settings
Executing Django with Specified Settings
When running Django commands, utilize the --settings option to specify the appropriate settings file:
Sample Project Template
For further guidance, a sample project layout template is available on GitHub.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3