关于Django的缩略图

我在Django的官方文档里看了一下,没有找到有关缩略图的官方库,不过在Django的Wiki里头倒是看到了一篇关于使用缩略图的介绍,请参考:https://code.djangoproject.com/wiki/ThumbNails

关于Problem的描述

The majority of applications that have images, probably use thumbnails in some capacity. There is no standard thumbnail capability in Django but there are a couple of different options out there that people have created. This page is an attempt to gather them in one place and discuss the best strategy for integrating one in Django.

Current Implementations

官方推荐的第三方库

关于easy_thumbnails

A powerful, yet easy to implement thumbnailing application for Django 1.8+ Below is a quick summary of usage. For more comprehensive information, view the full documentation online or the peruse the project's docs directory.

了解更多请打开easy_thumbnails的项目主页,链接在上面有,公众号推文不能点击链接请访问原文。

使用步骤简介

安装

pip install easy-thumbnails

配置 编辑settings.py

INSTALLED_APPS = (
    ...
    'easy_thumbnails',
)

THUMBNAIL_ALIASES = {
    '': {
        'avatar': {'size': (50, 50), 'crop': True},
    },
}

Run manage.py migrate easy_thumbnails.

在templates中使用

{% load thumbnail %}
<img src="{{ profile.photo|thumbnail_url:'avatar' }}" alt="" />

更多使用方法请参考官方文档