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
目录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
- sorl-thumbnail is excellent.
- SmileyChris's easy-thumbnails is also excellent.
- aino-convert a versatile solution for the fastidious.
- Nesh's Thumbnail
- image-kit a django-ish way of resizing images, with image models
- Here's a more simple filter from Django snippets - Simple filter
- In Ticket #4115 you will find a patch with a contrib.thumbnails package - good documented; read the Google Discussion mentioned above for some thoughts about the implementation.
- Quick tip for adding thumbnails - Blog posting
- Yet another approach to adding a thumbnail - CustomUploadAndFilters
- Snippet that creates thumbnails on-demand using dynamics methods - Snippet 619
- Yet another method to resize image on upload - Automatically resizing uploaded images
- Custom field for image resizing on upload - http://djangothumbnails.com/
- Template tag for resizing to exact dimensions: http://bitbucket.org/winsmith/django-thumbnail/wiki/Home
- Easy frontend filter for resizing on the fly (great for mobile and mediaqueries) django-imagefit
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
docsdirectory.
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-Import-Export插件控制数据导入流程
前言 之前写过两篇跟这个插件有关的文章,可以回顾一下: Django数据导入导出神器django-import-export使用 Django-Import-Export插件关于外键的处理 最近有个朋友留言问我一个关于django-import-export插件的问题 为了形象表达这个问题,我举个书籍管理的例子来描述一下 数据库表 | id | name | price | | ---- |
2022-09-02 · Django · 约 1 分钟
Django-Filter介绍与刁钻需求的实现方法
Django-Filter是一个非常好用的第三方库,很好的利用了Django ORM的特性,可以使用很少的代码就扩展原有的接口,实现多种筛选功能~ 场景 Model定义的部分代码,可以看到需求模型包括了 关键词 keyword、区域 region、需求状态 require_status,这三个字段 class Require(models.Model): 需求 keyword =
2021-12-18 · Django · 约 1 分钟
Django+Taro项目实现企业微信登录
前言 还是最近在做的一个小项目,后端用的是Django搭配RestFramework做接口,前端第一次尝试用京东开源的Taro框架来做多端(目前需要做用于企业微信的H5端和微信小程序) 本文记录一下企业微信登录的流程,上周看文档看得头晕晕的,其实很简单,封装好了就几行代码的事~ 两种方式 一种是先拼接好登录要用的地址authorize_url,回调地址设置成h5应用的网页入口,然后把authori
2022-04-08 · Django · 约 1 分钟
讨论
共 0 条加载评论中…