collecstatic 不推送到文件 S3

collecstatic does not push to files S3

编辑:

我发现从我的 settings.py 文件中删除 import django_heroku 允许我将我的静态文件推送到我的 AWS 存储桶。当我取消注释 import django_heroku 时,collectstatic 然后将我的文件推送到 staticfiles 文件夹。

manage.py collectstatic#import django_heroku:

You have requested to collect static files at the destination location as specified in your settings.

maange.py collectstaticimport django_heroku:

You have requested to collect static files at the destination location as specified in your settings: /path/to/project/staticfiles

我不知道这是为什么,也不知道如何解决。现在的问题是:如何 运行 在 Heroku 上为我的 django 应用程序收集静态信息?或者我是否需要 运行 我的 heroku 实例与 nostatic? (例如 runserver --nostatic

问题:

每当我 运行 python manage.py collectstatic 我所有的静态文件都放在 local 'staticfiles' 文件夹中。我已经设置 STATICFILES_STORAGE = myapp.aws.utils.StaticRootS3Boto3Storage 但是文件总是转到 'myapp/staticfiles'.

Settings.py:

AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_FILE_EXPIRE = 200
AWS_PRELOAD_METADATA = True
AWS_QUERYSTRING_AUTH = True

DEFAULT_FILE_STORAGE = 'myapp.aws.utils.MediaRootS3Boto3Storage'
STATICFILES_STORAGE = 'myapp.aws.utils.StaticRootS3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
S3DIRECT_REGION='us-east-1'

AWS_S3_URL = '//s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME

MEDIA_URL = 'http://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = MEDIA_URL

STATIC_URL = AWS_S3_URL + '/static/'
STATICFILES_LOCATION = STATIC_URL
MEDIAFILES_LOCATION = 'media'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

AWS_HEADERS = {
    'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
    'CacheControl': 'max-age=94608000',
}

myapp/aws/utils.py:

from storages.backends.s3boto3 import S3Boto3Storage

StaticRootS3Boto3Storage = lambda: S3Boto3Storage(location='static')
MediaRootS3Boto3Storage  = lambda: S3Boto3Storage(location='media')

项目结构:

myproject/
 |-- myapp/
 |    |-- aws/
 |    |    |-- __init__.py
 |    |    |-- utils.py
 |    |-- __init__.py
 |    |-- settings.py
 |    |-- urls.py
 |    +-- wsgi.py
 +-- manage.py
 |-- static/
 |   |-- scss
 |   |-- css
 |   |-- js
 |   |-- images
 |-- staticfiles/
 |    |-- **ALL STATIC FILES END UP HERE** 

备注:

问题:

我查阅过的资源:

对于遇到相同问题的任何人,我的解决方案是:django_heroku.settings(locals(), staticfiles=False)

which is also detailed at this github issue.