Skip to main content

Wagtail Lazy Images

Template tags that generate tiny blurry placeholder images alongside your wagtail images in order to lazy-load them medium.com style.

Installing

Install using pip: pip install wagtail-lazyimages

Usage

  1. Add wagtail_lazyimages to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'wagtail_lazyimages',
    ]
    
  2. Load the lazyimages_tags template tag library in your template:

    {% load "lazyimages_tags" %}
    
  3. Replace wagtail's image tag with lazy_image for images that should lazy load:

    {% lazy_image page.photo width-960 class="lazy" %}
    

    This template tag behaves just like wagtail's image tag with the exception that it generates an additional scaled down and blurred placeholder image. The URL of the placeholder image will appear in the src attribute of the image tag while the large version will be referenced in data-src:

    <img src="/path/to/placeholder-image.jpg" data-src"/path/to/image.jpg" class="lazy" />
    
  4. In the front end: Implement the lazy loading functionality yourself or use a dedicated JavaScript library like lozad.js:

    const observer = lozad('.lazy');
    observer.observe();
    

Alternative attribute

If you want to use a different attribute for referencing the original image than data-src use the parameter lazy_attr for that:

{% lazy_image page.photo width-960 lazy_attr="data-lazy-url" class="lazy" %}

As syntax

If you need to assign the image data to a template variable using Django's as syntax, the URL of the placeholder image is stored in the lazy_url attribute:

{% load "lazyimages_tags" %}

{% lazy_image page.photo width-960 as img %}

<img data-src="{{ img.url }}" src="{{ img.lazy_url }}" width="{{ img.width }}"
     height="{{ img.height }}" alt="{{ img.alt }}" />

attrs shortcut

In case you need to use Wagtail's attrs shortcut use lazy_attrs instead:

{% load "lazyimages_tags" %}

{% lazy_image page.photo width-960 as img %}

<img {{ img.lazy_attrs }} class="custom-class" />

Metadata

Release files for wagtail-lazyimages 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-lazyimages 0.1.8
File Size Uploaded Provenance Actions
wagtail-lazyimages-0.1.8.tar.gz 5.6 kB Without provenance Details for wagtail-lazyimages-0.1.8.tar.gz

Release files / wagtail-lazyimages-0.1.8.tar.gz

Download URL wagtail-lazyimages-0.1.8.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b960cb946f5f66e07445562718cf05f88f751ee13c7b179ce8993e56c10a9b4
BLAKE2b-256 checksum
How to use checksums
85dd005403bb0ade565d0eb7c3b020b62374fc24d6e83e2a3037962f229f18f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/3.6.9

Security for wagtail-lazyimages 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page