Skip to main content

Glide JS integration for Django

Project description

django-glide

This is a Django library to add support to Glide JS in your templates

It supports:

  • Django 3
  • Django 4
  • Django 5

Installation

pip install django-glide

Setup

First, add "django_glide" to your list of INSTALLED_APPS.

Then either in your base template (to load on all pages) or just in the template you need, add:

{% load glide_tags %}
{% glide_assets %}

Then to actually use a glide based carousel, use this in your template:

{% load glide_tags %}

...

{% glide_carousel my_images carousel_id="hero" type="carousel" perView=3 autoplay=3000 %}

All the options listed on the example above can be found here: https://glidejs.com/docs/options/ . Note that all options are using basic types such as integer, float or string, at the exception of the breakpoints field which is a complex object. Here is an example on how you can use it:

{% glide_carousel events carousel_id="events" type="carousel" perView=3.5 breakpoints='{"600": {"perView": 2.5}}' %}

And then in your view, return an object in the context following this format:

my_images = [
    {"image": "/static/img/slide1.jpg", "alt": "Slide 1"},
    {"image": "/static/img/slide2.jpg", "alt": "Slide 2"},
    {"image": "/static/img/slide3.jpg", "alt": "Slide 3"},
]

Using custom template

By default, the template shipped with the library is basic, it can either load an image or some text.

This library uses 2 templates, one for the carousel itself and one for each individual slides.

Slide template

You can set a global slide template by creating an HTML jinja file and referencing it in your settings like so:

GLIDE_DEFAULT_SLIDE_TEMPLATE = "myapp/slide.html"

Or you can set a slide template for a given carousel like so:

{% glide_carousel my_custom_data carousel_id="hero" slide_template="myapp/slide.html" type="carousel" perView=3 autoplay=3000 %}

Carousel template

You can set a global carousel template by creating an HTML jinja file and referencing it in your settings like so:

GLIDE_DEFAULT_CAROUSEL_TEMPLATE = "myapp/carousel.html"

Or you can set a carousel template for a given carousel like so:

{% glide_carousel my_custom_data carousel_id="hero" carousel_template="myapp/carousel.html" type="carousel" perView=3 autoplay=3000 %}

Changing the way GlideJS is loaded

By default, this library uses lastest Glide of the jsdelivr CDN, if you want to change this, you can modify one (or all) of the following settings:

GLIDE_JS_URL = "my new URL to fetch the JS"
GLIDE_CSS_CORE_URL = "my new URL to fetch the core CSS"
GLIDE_CSS_THEME_URL = "my new URL to fetch the theme CSS, if you set as None, it won't be loaded"

Development

Installing for development:

make install

Cleaning the installation:

make clean

Format the code:

make format

Check the code (for linting errors):

make check

Check the code (python type checker):

make static-check

Running all tests:

make test

Create a sdist+bdist package in dist/:

make package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_glide-0.4.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_glide-0.4.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django_glide-0.4.0.tar.gz.

File metadata

  • Download URL: django_glide-0.4.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_glide-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c6e9765d86da4a0a07927941491da7706f9a9b03ecfe99ec028ee5f1833031ee
MD5 453248b75afdbcf67082da7769199b1c
BLAKE2b-256 2431d7b245d7fa36fb77620ddfc2e85ec5df6778f6d83acab9b9cd2f41673b64

See more details on using hashes here.

File details

Details for the file django_glide-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: django_glide-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_glide-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d9c72b1c929885637cb367607551f02849ede8d29ac1acda3276a1c294e67ac
MD5 49ee55d1d714ea7fe9da0f08b3de4d94
BLAKE2b-256 b7b05752b84e64c44b6f0c19ffd045f001e57b6525b0e116b658b9367ba69f90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page