使用多個需求檔案

每個需求檔案都應與設定檔案的名稱匹配。讀取使用多個設定以獲取更多資訊。

結構體

djangoproject
├── config
│   ├── __init__.py
│   ├── requirements
│   │   ├── base.txt
│   │   ├── dev.txt
│   │   ├── test.txt
│   │   └── prod.txt
│   └── settings
└── manage.py

base.txt 檔案中,放置在所有環境中使用的依賴項。

# base.txt
Django==1.8.0
psycopg2==2.6.1
jinja2==2.8

在所有其他檔案中,包含與 -r base.txt 的基本依賴關係,並新增當前環境所需的特定依賴項。

# dev.txt
-r base.txt # includes all dependencies in `base.txt`

# specific dependencies only used in dev env
django-queryinspect==0.1.0
# test.txt
-r base.txt # includes all dependencies in `base.txt`

# specific dependencies only used in test env
nose==1.3.7
django-nose==1.4
# prod.txt
-r base.txt # includes all dependencies in `base.txt`

# specific dependencies only used in production env
django-queryinspect==0.1.0
gunicorn==19.3.0
django-storages-redux==1.3
boto==2.38.0

最後,安裝依賴項。例如,關於 dev env:pip install -r config/requirements/dev.txt