Skip to main content

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
  1. dom_id first argument can be string, instance or Model class
  2. dom_id second argument is optional string that will be used as prefix.

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>
  1. Please note ! can be used just like Javascript.
  2. So if user is not authenticated in this case, we would get <div class="inactive"></div>

This can help make css logic more organized.

Metadata

Release files for django-template-simplify 1.0.3

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

Source distribution (sdist)

Source distribution for django-template-simplify 1.0.3
File Size Uploaded Provenance Actions
django_template_simplify-1.0.3.tar.gz 3.3 kB Without provenance Details for django_template_simplify-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-template-simplify 1.0.3
File Interpreter ABI Platform Actions
django_template_simplify-1.0.3-py3-none-any.whl Python 3 none any Details for django_template_simplify-1.0.3-py3-none-any.whl

Total release size: 7.6 kB

Release files / django_template_simplify-1.0.3.tar.gz

Download URL django_template_simplify-1.0.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
acfe8f71d6695bc690edcfe95cb51166566a2f916f95f6ce106d1951575725c3
BLAKE2b-256 checksum
How to use checksums
c392cf6be933ee5e8017eb53db3d4f269e5c73b9fd94db70b3870fc8e59633db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / django_template_simplify-1.0.3-py3-none-any.whl

Download URL django_template_simplify-1.0.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4433d11ed26835ebfa88c76de9cb28a3fec52d727c092863fb711b56d221a526
BLAKE2b-256 checksum
How to use checksums
e01a7c0d1e08ae64c27781eab401bd419f87d1efb1b489f4a0a6ba83393bf18e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for django-template-simplify 1.0.3

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