我创建了一个production_settings.py
在其中放置所有生产环境变量和值的方法,例如:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
我以为我会声明一个环境变量,例如
MYPROJECT_PRODUCTION
并将其设置为
heroku config:add MYPROJECT_PRODUCTION=True
或者export MYPROJECT_PRODUCTION=True
在 settings.py (这是 django 创建的默认值)中,我想我会在文件末尾添加
import os
if os.environ.has_key('MYPROJECT_PRODUCTION') and os.environ.get('MYPROJECT_PRODUCTION')=='True':
from production_settings import *
这是这样做的正确方法吗?
我在尝试时遇到导入错误python manage shell
export DJANGO_SETTINGS_MODULE='myproject.settings'
export MYPROJECT_PRODUCTION=True
me@ubuntu:~/dev/python/django/myproject$ python manage.py shell
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)
manage.py 与 settings.py 存在于同一文件夹中..仍然发生错误。
我检查了echo $MYPROJECT_PRODUCTION
哪些输出True