Skip to content

Instantly share code, notes, and snippets.

@dangayle
Created July 29, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangayle/9605e167f8396210de27a6000f2982cf to your computer and use it in GitHub Desktop.
Save dangayle/9605e167f8396210de27a6000f2982cf to your computer and use it in GitHub Desktop.
Using lazysizes in Django
{% load static mogrify %}
<img
class="lazyload {{ class }}"
src="{% static 'sv3/img/spokesman-logo.png' %}"
data-sizes="auto"
data-srcset="
{% mogrify img_url resize '300x169' %} 300w,
{% mogrify img_url resize '530x298' %} 530w,
{% mogrify img_url resize '720x408' %} 720w,
{% mogrify img_url resize '1170x658' %} 1170w,"
alt="{{ img_alt }}" />
{% load static mogrify %}
<img
class="lazyload {{ class }}"
src="{% static 'sv3/img/spokesman-logo.png' %}"
data-sizes="auto"
data-srcset="
{% mogrify img_url thumbnail '300' %} 300w,
{% mogrify img_url thumbnail '530' %} 530w,
{% mogrify img_url thumbnail '720' %} 720w,
{% mogrify img_url thumbnail '1170' %} 1170w,"
alt="{{ img_alt }}" />
<figure>
<a href="{{ story.get_absolute_url }}">
{% include 'sv3/media/srcset_resize.html' with img_url=story.primary_photo.photo.url img_alt=story.primary_photo.get_pretty_caption|force_escape %}
<figcaption>{{ story.primary_photo.get_pretty_caption|safe }}</figcaption>
</a>
</figure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment