【发布时间】:2015-05-01 22:59:42
【问题描述】:
当我在 Heroku 上运行 collectstatic 时,我收到以下错误,因为我认为 collect static 正在尝试写入本地文件而不是使用 S3。
当我使用相同的 AWS 凭证在本地运行 collectstatic 时,我的静态文件会正确传输到我的 S3 存储桶。
另一个奇怪的是,我在 Heroku 上的媒体上传正确地保存在 S3 中。所以我知道我的 Django 应用程序可以很好地连接到 S3。
我已经进入 django shell,我已经导入了 DEFAULT_FILE_STORAGE 和 STATICFILES_STORAGE 并验证它们指向 storages.backends.s3boto.S3BotoStorage。
我还可以使用 boto 查看存储桶中的文件,
from storages.backends import s3boto
h = s3boto.S3BotoStorage()
h.bucket # Shows me my bucket name
通过 django 的交互式 shell,我可以列出存储桶中的文件和其他内容。
我不明白为什么在本地运行 collectstatic 有效,但是当我在 heroku 上运行时,使用相同的凭据、应用程序、环境等不起作用。但是我上传到 S3 的媒体确实适用于 heroku...?
这是我在 heroku 上运行 collectstatic 时遇到的错误,
Running `python manage.py collectstatic --noinput` attached to terminal... up, run.2485
/app/.heroku/python/lib/python3.3/site-packages/dotenv.py:53: UserWarning: Not reading .env - it doesn't exist.
warnings.warn("Not reading {0} - it doesn't exist.".format(dotenv))
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python3.3/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python3.3/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 111, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python3.3/site-packages/django/contrib/staticfiles/utils.py", line 27, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.3/site-packages/django/core/files/storage.py", line 270, in listdir
for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/static'
每次我推送到 heroku 时,我都会看到,
remote: -----> Preparing static assets
remote: Collectstatic configuration error. To debug, run:
remote: $ heroku run python ./manage.py collectstatic --noinput
remote:
【问题讨论】:
标签: python django heroku amazon-s3 boto