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+Logging:日志记录配置与使用方法
前言 日志在程序开发中是少不了的,通过日志我们可以分析到错误在什么地方,有什么异常。在生产环境下有很大的用途。在Java开发中通常用log4j,logback等第三方组件。那么在django中是怎么处理日志?django利用的就是Python提供的logging模块,但django中要用logging,还得有一定的配置规则,需要在setting中设置。 Logging模块 Logging模块为应用
2022-04-02 · Django · 约 1 分钟
Django中「强行」使用MVVM设计模式
扫盲 首先带大家了解一下什么是MVVM模式: 什么是MVVM?MVVM是Model-View-ViewModel的缩写。 MVVM是MVC的增强版,实质上和MVC没有本质区别,只是代码的位置变动而已 从名字上看,MVVM比MVC架构中多了一个ViewModel,没错,就是这个ViewModel,他是MVVM相对于MVC改进的核心思想。在开发过程中,由于需求的变更或添加,项目的复杂度越来越高,代码量
2021-12-18 · Django · 约 1 分钟
配置Django-TinyMCE组件支持上传图片功能
Django自带的Admin后台,好用,TinyMCE作为富文本编辑器,也蛮好用的,这两者结合起来在做博客的时候很方便(当然博客可能更适合用Markdown来写),但是Django-TinyMCE这个组件默认没有图片上传功能的,需要我们自己实现,本文将一步步带大家实现这个图片上传功能。 读者也可以举一反三实现其他需要和Django结合的功能。 编写上传图片逻辑 在任一views.py里添加代码:
2021-12-18 · Django · 约 1 分钟
一小时完成后台开发:DjangoRestFramework开发实践
DjangoRestFramework开发实践 在这之前我写过一篇关于Django与Drf快速开发实践的博客,Django快速开发实践:Drf框架和xadmin配置指北,粗略说了一下Drf配置和基本使用,不过里面只是涉及到最基本的CRUD,在正常的后端开发中涉及的诸如认证和权限、消息队列、缓存之类的操作,上一篇博客并没有涉及,这次开发我仔细了看了官方文档的这几个部分,把这部分的功能完善了起来。 D
2021-12-18 · Django · 约 1 分钟
讨论
共 0 条加载评论中…