返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
Django

Easily Create Image Thumbnails with easy_thumbnails

About Django Thumbnails I took a look at Django's official documentation and didn't find an official library for thumbnails. However, I did find an introduction to using thumbnails in the Django Wiki. Please refer to: https://code.djangoproject.com/wiki/ThumbNails Description of the Problem The majority of applications that have images, probably

曦远 (DealiAxy)约 10 分钟
目录5 个章节

About Django Thumbnails

I took a look at Django's official documentation and didn't find an official library for thumbnails. However, I did find an introduction to using thumbnails in the Django Wiki. Please refer to: https://code.djangoproject.com/wiki/ThumbNails

Description of the 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

Officially recommended third-party libraries

About 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.

To learn more, please open the easy_thumbnails project homepage. The link is above. If you cannot click links in WeChat official account posts, please visit the original article.

Brief Overview of Usage Steps

Installation

pip install easy-thumbnails

Configuration Edit settings.py

INSTALLED_APPS = (
    ...
    'easy_thumbnails',
)

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

Run manage.py migrate easy_thumbnails.

Usage in templates

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

For more usage methods, please refer to the official documentation

_EOF_

Easily Create Image Thumbnails with easy_thumbnails

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…