Skip to main content

Common useful django template tags and filters

Getting Started

Simply install, add to your INSTALLED_APPS setting and use {% load common_filters common_tags %} in your templates to enable access to the tags and filters

Installing

You can get Django Commontags by using pip or easy_install:

$ pip install django-commontags
or
$ easy_install django-commontags

If you want to install it from source, grab the git repository from github and run setup.py:

$ git clone git://github.com/Jaidan/django-commontags.git
$ cd django-commontags
$ python setup.py install

Included Tags and Filters

Tags

divide

Allows division of two numbers within a template. Accepts a numerator, denominator, and optional format string. Be aware that the format string cannot be a string literal and must be a context variable that contains the format string

dynamic_regroup

Extends the built in regroup tag to allow regrouping by a attribute named by a context variable’s value. Accepts an iterable, th vairable to be resolved to an attribute name, and the variable to write the result into.

Filters

percentage

Takes a value converts it to a float and returns the result formatted as a percentage. Accepts an integer for number of decimal places.

truncatechars

Takes a string value and truncates it to a given number of chars. Appends “…” to the truncated value. Accepts an integer for the number of characters to truncate to

partition

Break a list into n pieces. The last list may be larger than the rest if the list doesn’t break cleanly. That is:

>>> l = range(10)

>>> partition(l, 2)
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]

>>> partition(l, 3)
[[0, 1, 2], [3, 4, 5], [6, 7, 8, 9]]

>>> partition(l, 4)
[[0, 1], [2, 3], [4, 5], [6, 7, 8, 9]]

>>> partition(l, 5)
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
lookup

Looks up a value from a dictionary. This allows dictionary look ups based on a context variables value. Accepts the name to lookup.

unslugify

Attempts to roughly unslugify a string. Replaces ‘-’ and ‘_’ with ‘ ‘

Release files for django-commontags 0.1

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-commontags 0.1
File Size Uploaded
django-commontags-0.1.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-commontags 0.1
File Interpreter ABI Platform
django-commontags-0.1.linux-i686.exe Details

Total release size: 70.5 kB

Release files / django-commontags-0.1.tar.gz

Download URL django-commontags-0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
219ec1c4c20e578b0792e1d8a298eef52cbbab906b6b4e1c31db580a08cc26d3
BLAKE2b-256 checksum
How to use checksums
3326f663450e1f9c830aa57777252d734381fd6457033955b0930747af8ae9dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-commontags-0.1.linux-i686.exe

Download URL django-commontags-0.1.linux-i686.exe
Size 66.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f7cfa6e925ddd78f361528796d4704ddb0540c121ad5a1c56dd316552db2f5e1
BLAKE2b-256 checksum
How to use checksums
4d85b16bc1748515784524af07a8cabcb9d4363ab55732956ed4fe6c5144b013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

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