When I run collectstatic on Heroku I get the error below because I believe collect static is trying to write to a local file instead of using S3.
When I run collectstatic locally with the same AWS credentials my static files are properly transferred to my S3 bucket.
Another oddity is that my media upload on Heroku get saved in S3 properly. So I know my Django app is connecting to S3 just fine.
I've gone into the django shell and I've imported DEFAULT_FILE_STORAGE
& STATICFILES_STORAGE
and verified they point to storages.backends.s3boto.S3BotoStorage
.
I've also been able to use boto to view the files in my bucket,
from storages.backends import s3boto
h = s3boto.S3BotoStorage()
h.bucket # Shows me my bucket name
Through django's interactive shell I can list the files in my bucket and other things.
I can't figure out why running collectstatic locally works but when I run on heroku, using the same credentials, app, environment, etc doesn't work. But my media uploads to S3 do work on heroku...?
This the error I get running collectstatic on heroku,
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'
Every time I push to heroku I see,
remote: -----> Preparing static assets
remote: Collectstatic configuration error. To debug, run:
remote: $ heroku run python ./manage.py collectstatic --noinput
remote:
I found my error, it was stupid. It turns out my static files directory was being ignored in both my gitignore and my slugignore file.
Lesson learned, don't blindly copy other's gitignore and slugignore files...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.