Skip to main content

Common django template tags and filters

Project description

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 ‘ ‘

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-commontags-0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

django-commontags-0.1.linux-i686.exe (66.7 kB view details)

Uploaded Source

File details

Details for the file django-commontags-0.1.tar.gz.

File metadata

File hashes

Hashes for django-commontags-0.1.tar.gz
Algorithm Hash digest
SHA256 219ec1c4c20e578b0792e1d8a298eef52cbbab906b6b4e1c31db580a08cc26d3
MD5 a2f77e9258e3091edbbfe30c1b4534fa
BLAKE2b-256 3326f663450e1f9c830aa57777252d734381fd6457033955b0930747af8ae9dc

See more details on using hashes here.

File details

Details for the file django-commontags-0.1.linux-i686.exe.

File metadata

File hashes

Hashes for django-commontags-0.1.linux-i686.exe
Algorithm Hash digest
SHA256 f7cfa6e925ddd78f361528796d4704ddb0540c121ad5a1c56dd316552db2f5e1
MD5 a98c9aa565c22a7b4d3c68fa9c870ea9
BLAKE2b-256 4d85b16bc1748515784524af07a8cabcb9d4363ab55732956ed4fe6c5144b013

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page