Django 使用多个需求文件

示例

每个需求文件应与设置文件的名称匹配。阅读使用多种设置以获取更多信息。

结构体

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
-rbase.txt# includes all dependencies in `base.txt`

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

# specific dependencies only used in test env
nose==1.3.7
django-nose==1.4
# prod.txt
-rbase.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