sorl-thumbnail是第三方模块,主要用来将图片转换成缩略图展示。
安装:
pip install sorl-thumbnail
使用:
{% load thumbnail %}
{% thumbnail image.image '100x100' crop='center' as img %}
<img src="{{ img.url }}" width="{{ img.width }}"
height="{{ img.height }}">
{% endthumbnail %}
根据教程,然后重启服务器就OK,但是我重启后发现不起作用,
原因如下:
在重启之前,需要先迁移数据库,然后该模块才会工作。
sorl-thumbnail文档:
https://sorl-thumbnail.readthedocs.io/en/latest/
该模块除了作标签用,还可以作为普通逻辑代码使用,具体用法参见文档。
有用请点赞~