曦远 (DealiAxy)一份私人的文字刊物

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 许可协议。转载请注明出处!

相关文章

Django统一包装接口返回数据格式

前言 最近实在太忙了,开始了一个新的项目,为了快速形成产品,我选择了Django来实现后端,然后又拿起了之前我封装了项目脚手架「DjangoStarter」。 由于前段时间我写了不少.NetCore的后端代码,对CRUD的接口开发又有了一些新的理解,所以肯定也要把DjangoStarter改造一番,改得更加顺手~ 题外话:话说我在前端终于真正用上react,不得不说 ts + react 真好用,

2022-08-26 · Django · 约 1 分钟

Django+Taro项目实现企业微信登录

前言 还是最近在做的一个小项目,后端用的是Django搭配RestFramework做接口,前端第一次尝试用京东开源的Taro框架来做多端(目前需要做用于企业微信的H5端和微信小程序) 本文记录一下企业微信登录的流程,上周看文档看得头晕晕的,其实很简单,封装好了就几行代码的事~ 两种方式 一种是先拼接好登录要用的地址authorize_url,回调地址设置成h5应用的网页入口,然后把authori

2022-04-08 · Django · 约 1 分钟

讨论

共 0 条

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

加载评论中…