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