在Heroku上部署django cookiecutter模板

时间:2017-02-23 03:40:51

标签: django heroku cookiecutter-django

我正在尝试在Heroku上部署网络。 当我运行heroku run python manage.py migrate时,我会收到一些错误: django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable

我阅读了Cookiecutter上的文档,该文档说我必须指定这些值。但它并没有告诉我目的和方法是什么。我想知道我真的必须指定所有这些值吗?

DJANGO_AWS_ACCESS_KEY_ID    
DJANGO_AWS_SECRET_ACCESS_KEY    
DJANGO_AWS_STORAGE_BUCKET_NAME  
DJANGO_SENTRY_DSN
DJANGO_SENTRY_CLIENT
DJANGO_SENTRY_LOG_LEVEL 
DJANGO_MAILGUN_API_KEY  
DJANGO_MAILGUN_SERVER_NAME

日志:

$ heroku logs --app glacial-forest-93266 --dyno run.9155
2017-02-23T03:28:44.634830+00:00 heroku[run.9155]: Starting process with command `python manage.py migrate`
2017-02-23T03:28:45.292164+00:00 heroku[run.9155]: State changed from starting to up
2017-02-23T03:28:47.487454+00:00 heroku[run.9155]: Process exited with status 1
2017-02-23T03:28:47.336279+00:00 app[run.9155]: /app/.heroku/python/lib/python3.5/site-packages/environ/environ.py:608: UserWarning: /app/co
nfig/settings/.env doesn't exist - if you're not configuring your environment separately, create one.
2017-02-23T03:28:47.359554+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.359557+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 264, in ge
t_value
2017-02-23T03:28:47.336297+00:00 app[run.9155]:   "environment separately, create one." % env_file)
2017-02-23T03:28:47.359787+00:00 app[run.9155]:     value = self.ENVIRON[var]
2017-02-23T03:28:47.359791+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/os.py", line 683, in __getitem__
2017-02-23T03:28:47.360099+00:00 app[run.9155]:     raise KeyError(key) from None
2017-02-23T03:28:47.360103+00:00 app[run.9155]: KeyError: 'DJANGO_SENTRY_DSN'
2017-02-23T03:28:47.360105+00:00 app[run.9155]:
2017-02-23T03:28:47.360106+00:00 app[run.9155]: During handling of the above exception, another exception occurred:
2017-02-23T03:28:47.360107+00:00 app[run.9155]:
2017-02-23T03:28:47.360109+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.360130+00:00 app[run.9155]:   File "manage.py", line 23, in <module>
2017-02-23T03:28:47.360228+00:00 app[run.9155]:     execute_from_command_line(sys.argv)
2017-02-23T03:28:47.360246+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 367, in execute_from_command_line
2017-02-23T03:28:47.360425+00:00 app[run.9155]:     utility.execute()
2017-02-23T03:28:47.360427+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 359, in execute
2017-02-23T03:28:47.360606+00:00 app[run.9155]:     self.fetch_command(subcommand).run_from_argv(self.argv)
2017-02-23T03:28:47.360609+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 208, in fetch_command
2017-02-23T03:28:47.360739+00:00 app[run.9155]:     klass = load_command_class(app_name, subcommand)
2017-02-23T03:28:47.360740+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 40, in load_command_class
2017-02-23T03:28:47.360838+00:00 app[run.9155]:     module = import_module('%s.management.commands.%s' % (app_name, name))
2017-02-23T03:28:47.360960+00:00 app[run.9155]:     return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.360840+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module

2017-02-23T03:28:47.360962+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
2017-02-23T03:28:47.361192+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
2017-02-23T03:28:47.361105+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
2017-02-23T03:28:47.361278+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
2017-02-23T03:28:47.361364+00:00 app[run.9155]:   File "<frozen importlib._bootstrap_external>", line 662, in exec_module
2017-02-23T03:28:47.361554+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migr
ate.py", line 15, in <module>
2017-02-23T03:28:47.361466+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
2017-02-23T03:28:47.361645+00:00 app[run.9155]:     from django.db.migrations.autodetector import MigrationAutodetector
2017-02-23T03:28:47.361645+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/autodetector.py
", line 13, in <module>
2017-02-23T03:28:47.361739+00:00 app[run.9155]:     from django.db.migrations.questioner import MigrationQuestioner
2017-02-23T03:28:47.361740+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/questioner.py",
 line 12, in <module>
2017-02-23T03:28:47.361832+00:00 app[run.9155]:     from .loader import MigrationLoader
2017-02-23T03:28:47.361833+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/loader.py", lin
e 10, in <module>
2017-02-23T03:28:47.361923+00:00 app[run.9155]:     from django.db.migrations.recorder import MigrationRecorder
2017-02-23T03:28:47.361924+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 12, in <module>
2017-02-23T03:28:47.362014+00:00 app[run.9155]:     class MigrationRecorder(object):
2017-02-23T03:28:47.362015+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 26, in MigrationRecorder
2017-02-23T03:28:47.362109+00:00 app[run.9155]:     class Migration(models.Model):
2017-02-23T03:28:47.362110+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 27, in Migration
2017-02-23T03:28:47.362206+00:00 app[run.9155]:     app = models.CharField(max_length=255)
2017-02-23T03:28:47.362206+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1043, in __init__
2017-02-23T03:28:47.362557+00:00 app[run.9155]:     super(CharField, self).__init__(*args, **kwargs)
2017-02-23T03:28:47.362558+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 166, in __init__
2017-02-23T03:28:47.362682+00:00 app[run.9155]:     self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
2017-02-23T03:28:47.362683+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 53, i
n __getattr__
2017-02-23T03:28:47.362790+00:00 app[run.9155]:     self._setup(name)
2017-02-23T03:28:47.362791+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 41, i
n _setup
2017-02-23T03:28:47.362927+00:00 app[run.9155]:     self._wrapped = Settings(settings_module)
2017-02-23T03:28:47.362929+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 97, i
n __init__
2017-02-23T03:28:47.363042+00:00 app[run.9155]:     mod = importlib.import_module(self.SETTINGS_MODULE)
2017-02-23T03:28:47.363043+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module

2017-02-23T03:28:47.363153+00:00 app[run.9155]:     return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.363154+00:00 app[run.9155]:   File "/app/config/settings/production.py", line 161, in <module>
2017-02-23T03:28:47.363279+00:00 app[run.9155]:     SENTRY_DSN = env('DJANGO_SENTRY_DSN')
2017-02-23T03:28:47.363394+00:00 app[run.9155]:     return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
2017-02-23T03:28:47.363395+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 268, in ge
t_value
2017-02-23T03:28:47.363558+00:00 app[run.9155]:     raise ImproperlyConfigured(error_msg)
2017-02-23T03:28:47.363281+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 126, in __
call__
2017-02-23T03:28:47.363560+00:00 app[run.9155]: django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable
2017-02-23T03:28:47.501504+00:00 heroku[run.9155]: State changed from up to complete

2 个答案:

答案 0 :(得分:2)

您可以在此处查看所有必要的设置:http://cookiecutter-django.readthedocs.io/en/latest/settings.html

通常,您可以为它定义一个空白值,如:

  

heroku config:设置DJANGO_AWS_ACCESS_KEY_ID =''

具体来说,如果您不上传到S3,可以将 AWS 值留空,如果禁用哨兵,可以将 SENTRY 值留空,然后您可以离开如果您禁用mailgun,则 MAILGUN 应用。

答案 1 :(得分:0)

您正在使用/config/settings内的production.py设置,方法是运行以下行:

heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production'

为heroku创建一个单独的设置文件,而不是SENTRY和其他服务,否则只需取消注释初始化这些服务的行。 如果您不使用aw,那么您还希望保留/media/static本地。