Use heroicons in your Django and Jinja templates.

Related tags

Djangoheroicons
Overview

heroicons

https://img.shields.io/github/workflow/status/adamchainz/heroicons/CI/main?style=for-the-badge https://img.shields.io/codecov/c/github/adamchainz/heroicons/main?style=for-the-badge https://img.shields.io/pypi/v/heroicons.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

Use heroicons in your Django and Jinja templates.

Requirements

Python 3.6 to 3.9 supported.

Django 2.2 to 3.2 supported.


Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Usage

The heroicons package supports both Django templates and Jinja2 templates. Follow the appropriate guide below.

Django templates

  1. Install with python -m pip install heroicons[django].

  2. Add to your INSTALLED_APPS:

    INSTALLED_APPS = [
        ...,
        'heroicons',
        ...,
    ]

Now in your templates you can load the template library with:

{% load heroicons %}

This provides two tags to render <svg> icons: heroicon_outline and heroicon_solid, corresponding to the two icon styles in the set. The tags take these arguments:

  • name, positional: the name of the icon to use. You can see the icon names on the heroicons.com grid.
  • size, keyword: an integer that will be used for the width and height attributes of the output <svg> tag. Defaults to the icons’ designed sizes: 24 for outline and 20 for solid.
  • Any number of keyword arguments. These will be added as HTML attributes to the output <svg> tag. Underscores in attribute names will be replaced with dashes, allowing you to define e.g. data- attributes.

For example, to render an outline “academic-cap” icon, at 48x48, with some extra CSS classes and a data attribute “controller”, you would write:

{% heroicon_outline "academic-cap" size=48 class="h-4 w-4 inline" data_controller="academia" %}

Jinja templates

  1. Install with python -m pip install heroicons[jinja].

  2. Adjust your Jinja Environment to add the two global functions heroicon_outline and heroicon_solid, imported from heroicons.jinja. For example:

    from heroicons.jinja import heroicon_outline, heroicon_solid
    from jinja2 import Environment
    
    env = Environment()
    env.globals.update(
        {
            "heroicon_outline": heroicon_outline,
            "heroicon_solid": heroicon_solid,
        }
    )

Now in your templates you can call those two functions, which render <svg> icons corresponding to the two icon styles in the set. The functions take these arguments:

  • name, positional: the name of the icon to use. You can see the icon names on the heroicons.com grid.
  • size, keyword: an integer that will be used for the width and height attributes of the output <svg> tag. Defaults to the icons’ designed sizes: 24 for outline and 20 for solid.
  • Any number of keyword arguments. These will be added as HTML attributes to the output <svg> tag. Underscores in attribute names will be replaced with dashes, allowing you to define e.g. data- attributes.

For example, to render an outline “academic-cap” icon, at 48x48, with some extra CSS classes and a data attribute “controller”, you would write:

{{ heroicon_outline("academic-cap", size=48, class="h-4 w-4 inline", data_controller="academia") %}
Owner
Adam Johnson
🦄 @django technical board member 🇬🇧 @djangolondon co-organizer ✍ AWS/Django/Python Author and Consultant
Adam Johnson
Social Media Network Focuses On Data Security And Being Community Driven Web App

privalise Social Media Network Focuses On Data Security And Being Community Driven Web App The Main Idea: We`ve seen social media web apps that focuse

Privalise 8 Jun 25, 2021
A debug/profiling overlay for Django

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

David Cramer 228 Oct 17, 2022
Packs a bunch of smaller CSS files together from 1 folder.

Packs a bunch of smaller CSS files together from 1 folder.

1 Dec 09, 2021
Built from scratch to replicate some of the Django admin functionality and add some more, to serve as an introspective interface for Django and Mongo.

django-mongonaut Info: An introspective interface for Django and MongoDB. Version: 0.2.21 Maintainer: Jazzband (jazzband.co) This Project is Being Mov

Jazzband 238 Dec 26, 2022
Login System Django

Login-System-Django Login System Using Django Tech Used Django Python Html Run Locally Clone project git clone https://link-to-project Get project for

Nandini Chhajed 6 Dec 12, 2021
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

django-quill-editor django-quill-editor makes Quill.js easy to use on Django Forms and admin sites No configuration required for static files! The ent

lhy 139 Dec 05, 2022
Django datatables with htmx.

Django datatables with htmx.

Regis Santos 7 Oct 23, 2022
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
Sistema administrador de contranas desarrollador en Django

Sistema Contrasenas Desarrolado en Django Proyecto sistema de administracion de contraseñas, de la experiencia educativa Programacion Segura Descripci

Ibrain Rodriguez Espinoza 1 Sep 24, 2022
No effort, no worry, maximum performance.

Django Cachalot Caches your Django ORM queries and automatically invalidates them. Documentation: http://django-cachalot.readthedocs.io Table of Conte

NoriPyt 980 Jan 06, 2023
An automatic django's update checker and MS teams notifier

Django Update Checker This is small script for checking any new updates/bugfixes/security fixes released in django News & Events and sending correspon

prinzpiuz 4 Sep 26, 2022
A music recommendation REST API which makes a machine learning algorithm work with the Django REST Framework

music-recommender-rest-api A music recommendation REST API which makes a machine learning algorithm work with the Django REST Framework How it works T

The Reaper 1 Sep 28, 2021
Cached file system for online resources in Python

Minato Cache & file system for online resources in Python Features Minato enables you to: Download & cache online recsources minato supports the follo

Yasuhiro Yamaguchi 10 Jan 04, 2023
Adding Firebase Cloud Messaging Service into a Django Project

Adding Firebase Cloud Messaging Service into a Django Project The aim of this repository is to provide a step-by-step guide and a basic project sample

Seyyed Ali Ayati 11 Jan 03, 2023
This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS.

I-P-L-Team-Project This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS. Screenshots HO

1 Dec 15, 2021
It takes time to start a Django Project and make it almost production-ready.

It takes time to start a Django Project and make it almost production-ready. A developer needs to spend a lot of time installing required libraries, setup a database, setup cache as well as hiding se

Khan Asfi Reza 1 Jan 01, 2022
A simple plugin to attach a debugger in Django on runserver command.

django-debugger A simple plugin to attach a debugger in Django during runserver Installation pip install django-debugger Usage Prepend django_debugger

Sajal Shrestha 11 Nov 15, 2021
Agenda feita usando o django para adicionar eventos

Agenda de Eventos Projeto Agenda com Django Inicio O projeto foi iniciado no Django, usando o models.py foi adicionado os dados dos eventos e feita as

Bruno Fernandes 1 Apr 14, 2022
The new Python SDK for Sentry.io

Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoy

Sentry 1.4k Jan 05, 2023
Indonesia's negative news detection using gaussian naive bayes with Django+Scikir Learn

Introduction Indonesia's negative news detection using gaussian naive bayes build with Django and Scikit Learn. There is also any features, are: Input

Harifzi Ham 1 Dec 30, 2021