django 上传 缩略图_使用django-thumbnail-works生成图像缩略图。

本文介绍了如何使用django-thumbnail-works在Django应用中创建图像缩略图。首先,通过pip安装该包及其依赖,如PIL。然后,更新模型,将ImageField替换为ThumbnailField,并定义所需的缩略图大小和处理选项。最后,可以在模板中直接访问缩略图字段来展示它们。
摘要由CSDN通过智能技术生成

django 上传 缩略图

Uploading images to our Django application can be as easy as adding an ImageField to our model. However, ImageField falls short in one key aspect, thumbnails. Usually when uploading images, we want to create smaller versions for them, for using in for example, galleries or previews. This however, has to be done manually using the appropriate imaging libraries available.

将图像上传到我们的Django应用程序就像将ImageField添加到我们的模型一样容易。 但是, ImageField在一个关键方面(缩略图)不足。 通常,在上载图像时,我们希望为其创建较小的版本,例如在画廊或预览中使用。 但是,必须使用适当的可用成像库手动完成此操作。

Enter django-thumbnail-works:

输入django-thumbnail-works:

The django-thumbnail-works package can solve this for us by providing the EnahncedImageField class. We can easily replace all of the ImageFields in our models with EnhancedImageFields (which actually subclasses Django’s ImageField), and pass the additional arguments that describe what has to be done to the image after uploading.

django-thumbnail-works软件包可以通过提供EnahncedImageField类为我们解决这个问题。 我们可以轻松地将模型中的所有ImageFields替换为EnhancedImageFields (实际上是Django的ImageField子类),然后将附加参数传递给上传后的图像,这些附加参数描述了必须执行的操作。

Here are the steps for getting django-thumbnails-works up and running in no time:

以下是立即启动django-thumbnails-works并运行的步骤:

1.首先,安装 (1. First things first, installation)

Installing django-thumbnail-works should be as easy as using pip to install the package was well as its dependencies, cropresize and PIL, the python imaging library.

安装django-thumbnail-works应该和使用pip来安装软件包一样容易,并且要依赖其依赖项, cropresize和python映像库PIL

pip install 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值