此問題與使用Heroku,django-storages(w/boto for s3)以及CloudFront用於靜態內容的設置有關。無法通過Heroku使用boto-s3桶收集靜態到s3返回無類型
我一直在嘗試過去的幾個小時成功地加載我的靜態文件到我的Heroku應用程序。我已經成功地將Cloudfront掛鉤到了我的s3存儲桶,並且看起來好像存儲桶已正確設置,但無論出於何種原因,我的AWS_STORAGE_BUCKET_NAME
值似乎都沒有正確註冊。
如果任何人有任何關於如何調試的線索或想法,我會非常感激。我不知道該怎麼做。謝謝閱讀。
settings.py(重要的東西):
try:
from settings_local import *
except:
import s3utils
DEBUG = False
#s3 stuff
DEFAULT_FILE_STORAGE = 's3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 's3utils.StaticRootS3BotoStorage'
STATIC_URL = 'https://[domain].cloudfront.net/'
#use heroku postgres database
import dj_database_url
DATABASES['default'] = dj_database_url.config()
s3utils.py
from storages.backends.s3boto import S3BotoStorage
from django.utils.functional import SimpleLazyObject
import os
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
AWS_STORAGE_BUCKET_NAME = 'static.[website].org'
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
這是回溯試圖collectstatic當我得到,或者通過 'Heroku上運行' 或Procfile:
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 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 113, in collect
handler(path, prefixed_path, storage)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 287, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 215, in delete_file
if self.storage.exists(prefixed_path):
File "/app/.heroku/python/lib/python2.7/site-packages/storages/backends/s3boto.py", line 284, in exists
return k.exists()
File "/app/.heroku/python/lib/python2.7/site-packages/boto/s3/key.py", line 399, in exists
return bool(self.bucket.lookup(self.name))
File "/app/.heroku/python/lib/python2.7/site-packages/boto/s3/bucket.py", line 148, in lookup
return self.get_key(key_name, headers=headers)
File "/app/.heroku/python/lib/python2.7/site-packages/boto/s3/bucket.py", line 181, in get_key
query_args=query_args)
File "/app/.heroku/python/lib/python2.7/site-packages/boto/s3/connection.py", line 458, in make_request
auth_path = self.calling_format.build_auth_path(bucket, key)
File "/app/.heroku/python/lib/python2.7/site-packages/boto/s3/connection.py", line 92, in build_auth_path
path = '/' + bucket
TypeError: cannot concatenate 'str' and 'NoneType' objects
請注意,我省略了域名等,我實際上沒有[域]或代碼中的[網站]。
我不想說我回答這個問題,因爲它真的不是一個滿意的答案,爲什麼這個問題是存在的,但只是: 'AWS_ACCESS_KEY_ID = os.environ [「AWS_ACCESS_KEY_ID」] AWS_SECRET_ACCESS_KEY = os.environ ['AWS_SECRET_ACCESS_KEY'] AWS_STORAGE_BUCKET_NAME ='static。[website] .org'' settings.py在我的try/except塊似乎工作之前。任何能夠更好地理解Python的人都能解釋爲什麼會出現這種情況? –