How to manage local vs production settings in Django?

前端 未结 22 2085
别跟我提以往
别跟我提以往 2020-11-22 15:00

What is the recommended way of handling settings for local development and the production server? Some of them (like constants, etc) can be changed/accessed in both, but s

22条回答
  •  猫巷女王i
    2020-11-22 15:21

    For most of my projects I use following pattern:

    1. Create settings_base.py where I store settings that are common for all environments
    2. Whenever I need to use new environment with specific requirements I create new settings file (eg. settings_local.py) which inherits contents of settings_base.py and overrides/adds proper settings variables (from settings_base import *)

    (To run manage.py with custom settings file you simply use --settings command option: manage.py --settings=settings_you_wish_to_use.py)

提交回复
热议问题