A set of tools to help simplify your Django templates.
Project description
README
A set of tools to help simplify your Django templates
$ pip install django-template-simplify
Then add the app into INSTALLED_APPS
in settings.py
INSTALLED_APPS = [
...,
'template_simplify',
]
dom_id
dom_id
is a helper method that returns a unique DOM ID based on the object's class name and primary key.
{% load template_simplify %}
{% dom_id instance %} -> task_1
{% dom_id instance 'detail' %} -> detail_task_1
{% dom_id Task %} -> new_task
dom_id
first argument can be string, instance or Model classdom_id
second argument is optional string that will be used asprefix
.
You can also use it in your Django view code.
from template_simplify import dom_id
target = dom_id(instance, "detail_container")
We can say goodbye to id="task-{{ task.pk }}"
and use id="{% dom_id task %}"
instead.
The benefit is, it simplified the DOM ID generation in Python and Django template, and avoid typo error in many cases.
class_names
Inspired by JS classnames and Rails class_names
class_names
can help conditionally render css classes
{% load template_simplify %}
<div class="{% class_names test1=True 'test2' ring-slate-900/5=True already-sign-in=request.user.is_authenticated %}"></div>
'<div class="test1 test2 ring-slate-900/5 dark:bg-slate-800 %}"></div>'
It can also work well with TailwindCSS's some special char such as /
and :
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_template_simplify-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 116df19d3170ea32ccd1803850804c405f21efa60accb5538ebd535ca0deb5d5 |
|
MD5 | 122639ac6caa110f5913215c8ec11160 |
|
BLAKE2b-256 | a372fc02d8c1bf3bcb3ee31a9ed4effc44d027203efe612c1916f4753135feef |
Hashes for django_template_simplify-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aad1cac2e1c1fdf3aac0689ee1195d12ddbe446c85066b025c1feb43f3888526 |
|
MD5 | 33c9288fbcf70463e2e98843c3dbb89f |
|
BLAKE2b-256 | a959f1db3a79b86fae4d6c0c83c3ca6b650c0d6d6fe1e662613966cf30e612cc |