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_idfirst argument can be string, instance or Model classdom_idsecond 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 work well with TailwindCSS's some special char such as / and :
Below is an example of if else
<div class="{% class_names active=request.user.is_authenticated inactive=!request.user.is_authenticated %}"></div>
- Please note
!can be used just like Javascript. - So if user is not authenticated in this case, we would get
<div class="inactive"></div>
This can help make css logic more organized.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_template_simplify-1.0.3.tar.gz.
File metadata
- Download URL: django_template_simplify-1.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acfe8f71d6695bc690edcfe95cb51166566a2f916f95f6ce106d1951575725c3
|
|
| MD5 |
944cc758d4aa50e64fbf8410b1c1351f
|
|
| BLAKE2b-256 |
c392cf6be933ee5e8017eb53db3d4f269e5c73b9fd94db70b3870fc8e59633db
|
File details
Details for the file django_template_simplify-1.0.3-py3-none-any.whl.
File metadata
- Download URL: django_template_simplify-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4433d11ed26835ebfa88c76de9cb28a3fec52d727c092863fb711b56d221a526
|
|
| MD5 |
f9eb7767608b956a6d950cb61c051e80
|
|
| BLAKE2b-256 |
e01a7c0d1e08ae64c27781eab401bd419f87d1efb1b489f4a0a6ba83393bf18e
|