How to properly runserver on different settings for Django?

前端 未结 7 966
悲哀的现实
悲哀的现实 2021-02-07 14:42

I have a basic django rest API. I want to separate some of my settings for dev and prod just for organizational purposes. I\'m also just learning about separating environments.

7条回答
  •  时光取名叫无心
    2021-02-07 15:36

    Replace settings.py with dev.py on dev server and prod.py on production server.

    now in init.py files write code

    try:
        print("Trying import production.py settings...")
        from .prod import *
    except ImportError:
        print("Trying import development.py settings...")
        from .dev import *
    

    it find prod.py in production server and import it. On dev server it not find and prod.py and import dev.py

    then you don't need to specify configuration file name while running runserver command.

提交回复
热议问题