【问题标题】:Django on heroku with imagekit saving to AWS S3 is very slowheroku 上的 Django 和 imagekit 保存到 AWS S3 非常慢
【发布时间】:2012-03-24 00:15:48
【问题描述】:

我的 django 应用程序在 heroku(使用 gunicorn 运行)上,带有一个简单的共享数据库,并且图像被保存到 s3。问题是一旦页面有多个图像,响应就会变得非常缓慢(30-60 秒)。关于在这种情况下的最佳做法有什么提示吗?

设置:

#AWS login details etc
from S3 import CallingFormat
AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN

基本模型如下所示:

models.py

class TestModel(models.Model):
    original_image = models.ImageField(storage=s3_storage, upload_to='uploads/%Y/%m/%d')
    thumb_image = ImageSpec([resize.Fit(402)], image_field='original_image', storage=s3_storage, format='JPEG', options={'quality': 90})
    formatted_image = ImageSpec([resize.Fit(800)], image_field='original_image', storage=s3_storage, format='JPEG', options={'quality': 90})

和简化视图:

views.py

def home(request):
    images = TestModel.objects.filter(published=True)
    ctxt = {}
    ctxt['image'] = images
    return render_to_response('home.html', ctxt, RequestContext(request))

模板:

    {% for image in images %}
      <img src="{{ image.thumb_image.url }}" alt="">
    {% endfor %}

【问题讨论】:

标签: django heroku amazon-s3 amazon-web-services django-imagekit


【解决方案1】:

我猜这是因为您在网络测功机中直接调整图像大小,不是吗?

应该在工人测功机中完成。

【讨论】:

    猜你喜欢
    • 2016-05-16
    • 2018-07-13
    • 1970-01-01
    • 2018-08-02
    • 2021-12-17
    • 2021-04-27
    • 2020-12-22
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多