How do you configure Django for simple development and deployment?

后端 未结 14 1599
闹比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:52

    Personally, I use a single settings.py for the project, I just have it look up the hostname it's on (my development machines have hostnames that start with "gabriel" so I just have this:

    import socket
    if socket.gethostname().startswith('gabriel'):
        LIVEHOST = False
    else: 
        LIVEHOST = True
    

    then in other parts I have things like:

    if LIVEHOST:
        DEBUG = False
        PREPEND_WWW = True
        MEDIA_URL = 'http://static1.grsites.com/'
    else:
        DEBUG = True
        PREPEND_WWW = False
        MEDIA_URL = 'http://localhost:8000/static/'
    

    and so on. A little bit less readable, but it works fine and saves having to juggle multiple settings files.

提交回复
热议问题