【问题标题】:Heroku Collectstatic Timeout with Django AppHeroku Collectstatic Timeout with Django App
【发布时间】:2014-03-14 23:41:41
【问题描述】:

遇到一个意外问题,我最近尝试在 Heroku 上为应用运行 collectstatic 无限期超时:

Running `python manage.py collectstatic` attached to terminal... up, run.6250
/app/.heroku/python/lib/python2.7/site-packages/dotenv.py:16: UserWarning: not reading .env -   it doesn't exist.
warnings.warn("not reading %s - it doesn't exist." % dotenv)

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

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

我输入“是”后,它挂起并超时,没有错误。当我附加 --dry-run --noinput 时也会发生同样的事情。我的 env.txt 文件包括

AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY
AWS_QUERYSTRING_AUTH = False

我很困惑,因为我的代码没有任何变化,而且我之前已经成功地用这个应用程序运行了一个 collectstatic。

应用程序正在使用 django-storage 而不是 S3-boto。这是我的设置:

if DEBUG:
    #dev storage using local
    ...

else:
    # Production AWS S3    
    STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    AVATAR_STORAGE_DIR = 'avatars/'

    AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
    AWS_QUERYSTRING_AUTH = env('AWS_QUERYSTRING_AUTH', False)
    AWS_PRELOAD_METADATA = True

    STATIC_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
    MEDIA_URL = STATIC_URL
    ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

所有 AWS 凭证都在 Heroku 配置中设置。 FWIW 我有

heroku labs:enable user-env-compile 

启用

【问题讨论】:

    标签: django heroku amazon-s3 static-files


    【解决方案1】:

    collectfast 添加到您的requirements.txt 文件和settings.py(并检查installation docs)。这是一个救命稻草,特别是如果您有很多文件,因为它使用您的缓存设置来存储以前上传的文件的哈希值。将它添加到我的一些 Django 项目中极大地改进了静态文件集合(在 Heroku 的情况下,实际上使它变得可行)。

    【讨论】:

      猜你喜欢
      • 2017-05-30
      • 2015-07-17
      • 1970-01-01
      • 2020-09-14
      • 2021-10-13
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      相关资源
      最近更新 更多