How do you configure Django for simple development and deployment?

后端 未结 14 1596
闹比i
闹比i 2020-11-30 16:14

I tend to use SQLite when doing Django development, but on a live server something more robust is often needed (MySQL/PostgreSQL, for example). Invariably, there are other c

14条回答
  •  被撕碎了的回忆
    2020-11-30 16:32

    I have my settings.py file in an external directory. That way, it doesn't get checked into source control, or over-written by a deploy. I put this in the settings.py file under my Django project, along with any default settings:

    import sys
    import os.path
    
    def _load_settings(path):    
        print "Loading configuration from %s" % (path)
        if os.path.exists(path):
        settings = {}
        # execfile can't modify globals directly, so we will load them manually
        execfile(path, globals(), settings)
        for setting in settings:
            globals()[setting] = settings[setting]
    
    _load_settings("/usr/local/conf/local_settings.py")
    

    Note: This is very dangerous if you can't trust local_settings.py.

提交回复
热议问题