如何设置的Django-COM pressor在Heroku上,线下融为一体pression到S3 [英] How to setup django-compressor on heroku, offline compression to S3

查看:189
本文介绍了如何设置的Django-COM pressor在Heroku上,线下融为一体pression到S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着上SO发现每一个QA的建议,并在不同的博客,一切工程确定我开发的机器无法工作在Heroku上。

I followed every QA suggestions found on SO and in different blogs, Everything works ok on my dev machine and nothing works on heroku.

下面是我的设置:

DEFAULT_FILE_STORAGE = 'arena.utils.MediaRootS3BotoStorage' # media files
# storage

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_PRELOAD_METADATA = True # necessary to fix manage.py collectstatic command to only upload changed files instead of all files

S3_URL = 'https://%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = S3_URL + '/media/'

STATIC_URL = S3_URL + '/static/'

ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'


COMPRESS_URL = STATIC_URL
COMPRESS_OFFLINE = True
COMPRESS_STORAGE = 'utils.CachedS3BotoStorage'
STATICFILES_STORAGE = COMPRESS_STORAGE

当我运行collectstatic / COM preSS一切都很好,我看到这些文件被收集到S3并放在适当的地方。我看到清单文件。

When i run collectstatic/compress everything is ok, i see the files being collected to S3 and put in proper places. I see the manifest file.

装入有COM pressor标签的任何页面,显示错误 OfflineGenerationError:您已启用脱机COM pression但关键的d2a53169c44dec41ce3ee7da19b2b9d4从线下明显缺少运行蟒蛇manage.py COM preSS 再解决不了任何问题。当我检查清单文件,实际上它会查找键不存在。

Loading any page with compressor tag, show an error OfflineGenerationError: You have offline compression enabled but key "d2a53169c44dec41ce3ee7da19b2b9d4" is missing from offline manifest. Running python manage.py compress again solves nothing. when i check the manifest file, indeed the key it looks for doesn't exist.

这是怎么回事错在这里?

What is going wrong here?

问题我已经检查:

<一个href="http://stackoverflow.com/questions/7698406/how-to-configure-django-com$p$pssor-and-django-staticfiles-with-amazons-s3">How配置Django的COM pressor和Django的staticfiles与Amazon的S3?

的Django的COM pressor与S3网址Heroku的

<一个href="http://stackoverflow.com/questions/10316131/configuring-django-com$p$pssor-with-remote-storage-django-storage-amazon-s3">Configuring Django的COM pressor与远程存储(Django的存储 - Amazon S3的)

推荐答案

在我的身边,我有非常相似的配置,并且我成功地使用COM pressor超过2年。

On my side I have very similar config, and I'm successfully using compressor for more than 2 years.

settings.py

COMPRESS_STORAGE = 'MyAwesomeApp.app.CachedS3BotoStorage.CachedS3BotoStorage'

AWS_ACCESS_KEY_ID = '#######'
AWS_SECRET_ACCESS_KEY = '########################+#########+BqoQ'
AWS_STORAGE_BUCKET_NAME = 'myAmazonS3cdn.myawesomewebsite.com'
AWS_S3_SECURE_URLS = False
AWS_QUERYSTRING_AUTH = False

COMPRESS_ROOT = 'MyAwesomeApp/static'
STATIC_ROOT = 'MyAwesomeApp/static/javascript'
COMPRESS_OUTPUT_DIR = 'compressed'
STATICFILES_STORAGE = COMPRESS_STORAGE

STATIC_URL = "http://myAmazonS3cdn.myawesomewebsite.com/"
COMPRESS_URL = STATIC_URL
COMPRESS_ENABLED = True

CachedS3BotoStorage.py

from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage

from django.core.files.base import File

class CachedS3BotoStorage(S3BotoStorage):
    """
    S3 storage backend that saves the files locally, too.
    """
    def __init__(self, *args, **kwargs):
        super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
        self.local_storage = get_storage_class("compressor.storage.CompressorFileStorage")()

    def save(self, name, content):
        name = super(CachedS3BotoStorage, self).save(name, content)
        self.local_storage._save(name, content)
        return name

我跑蟒蛇managep.py COM preSS 本地,并有明显的对我的静态文件目录下生成。 Heroku的只处理collecstatic并提供最新的清单版本到我的CDN。

I'm running python managep.py compress locally, and having manifest generated on my static files directory. Heroku only deals with the collecstatic and delivers the most recent manifest version to my cdn.

问候,

这篇关于如何设置的Django-COM pressor在Heroku上,线下融为一体pression到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆