django settings per application - best practice?

后端 未结 4 533
忘了有多久
忘了有多久 2021-02-01 12:58

this is somewhat related to this question
Why is django's settings object a LazyObject?

In my django project i have several applications. Each application can ha

4条回答
  •  渐次进展
    2021-02-01 13:39

    My site is just starting and I want a the simplest but flexible configuration solution. That's what I came across with.

    # in the end of the site's settings.py
    . . .
    # Custom settings
    MYAPP_CONFIG_FILE = "/home/user/config/myapp_config.ini"
    

    In my application's models.py:

    from django.conf import settings
    import configparser
    
    config = configparser.ConfigParser()
    config.read(settings.MYAPP_CONFIG_FILE, encoding='utf_8')
    

    This config parser is described here. It's convenient enough but definitely not the only option.

提交回复
热议问题