Sorl-thumbnail to generate thumbnails in Django

pip install sorl-thumbnail

python manage.py makemigrations thumbnail

python manage.py migrate thumbnail

pip install Pillow

{% load thumbnail %}

{% thumbnail item.image ‘200x100’ as im %}
<img src=’{{ im.url }}’>
{% endthumbnail %}

{% thumbnail item.image ‘100x100’ padding=True as im %}

{{ item.image|is_portrait }}

{% thumbnail item.image ‘100x100’ as im %}
<img src=’{{ im.url }}’ style=’margin:{{ im|margin:”100x100" }}’>
{% endthumbnail %}

<img src=”{{ item.image.url|resolution:’2x’ }}”>
<img src=”{{ item.image.url|resolution:’1.5x’ }}”>

python manage.py thumbnail cleanup

python manage.py thumbnail clear

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store