How to manage local vs production settings in Django?

前端 未结 22 1917
别跟我提以往
别跟我提以往 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条回答
  •  Happy的楠姐
    2020-11-22 15:08

    In order to use different settings configuration on different environment, create different settings file. And in your deployment script, start the server using --settings= parameter, via which you can use different settings on different environment.

    Benefits of using this approach:

    1. Your settings will be modular based on each environment

    2. You may import the master_settings.py containing the base configuration in the environmnet_configuration.py and override the values that you want to change in that environment.

    3. If you have huge team, each developer may have their own local_settings.py which they can add to the code repository without any risk of modifying the server configuration. You can add these local settings to .gitnore if you use git or .hginore if you Mercurial for Version Control (or any other). That way local settings won't even be the part of actual code base keeping it clean.

提交回复
热议问题