How to manage local vs production settings in Django?

前端 未结 22 2079
别跟我提以往
别跟我提以往 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:29

    I am also working with Laravel and I like the implementation there. I tried to mimic it and combining it with the solution proposed by T. Stone (look above):

    PRODUCTION_SERVERS = ['*.webfaction.com','*.whatever.com',]
    
    def check_env():
        for item in PRODUCTION_SERVERS:
            match = re.match(r"(^." + item + "$)", socket.gethostname())
            if match:
                return True
    
    if check_env():
        PRODUCTION = True
    else:
        PRODUCTION = False
    
    DEBUG = not PRODUCTION
    

    Maybe something like this would help you.

提交回复
热议问题