How to manage local vs production settings in Django?

前端 未结 22 2049
别跟我提以往
别跟我提以往 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条回答
  •  清歌不尽
    2020-11-22 15:10

    I manage my configurations with the help of django-split-settings.

    It is a drop-in replacement for the default settings. It is simple, yet configurable. And refactoring of your exisitng settings is not required.

    Here's a small example (file example/settings/__init__.py):

    from split_settings.tools import optional, include
    import os
    
    if os.environ['DJANGO_SETTINGS_MODULE'] == 'example.settings':
        include(
            'components/default.py',
            'components/database.py',
            # This file may be missing:
            optional('local_settings.py'),
    
            scope=globals()
        )
    

    That's it.

    Update

    I wrote a blog post about managing django's settings with django-split-sttings. Have a look!

提交回复
热议问题