我正在尝试将我的Django网站部署到Heroku和Amazon S3上。但是,在我输入git push heroku master后,我得到了这个:
Counting objects: 4, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 408 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing dependencies with pip
remote:
remote: -----> Preparing static assets
remote: Collectstatic configuration error. To debug, run:
remote: $ heroku run python ./manage.py collectstatic --noinput
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 52.0MB
remote: -----> Launching... done, v10
remote: https://article-django.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/article-django.git
070a1af..c4bbac5 master -> master
然后我做了heroku run python ./manage.py collectstatic --noinput
并得到了这个追溯:
Running `python ./manage.py collectstatic --noinput` attached to terminal... up, run.8499
/app/static/
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django /core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 94, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/django_test/settings.py", line 142, in <module>
AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
File "/app/.heroku/python/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'AWS_STORAGE_BUCKET_NAME'
我也有我的Procfile:
web: gunicorn django_test.wsgi
我的settings.py文件的片段:
try:
from local_settings import *
except Exception as e:
print e.message
if not DEBUG:
AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/assets/' % article-deanna
STATIC_URL = S3_URL
我提交了所有更改,但我不知道为什么我仍然遇到此错误。
答案 0 :(得分:2)
您需要在Heroku上设置AWS_STORAGE_BUCKET_NAME
environment variable。
尝试以下操作(插入S3存储桶的名称):
heroku config:set AWS_STORAGE_BUCKET_NAME=<YOUR BUCKET NAME>