a jinja2 extension to use humanize library inside jinja2 templates
Project description
What is it ?
This is a jinja2 extension to use humanize library inside jinja2 templates.
Syntax
The generic syntax is {{ 'VALUE'|humanize_{humanize_fn}([humanize_fn_args]) }}
.
Following humanize functions are currently mapped:
naturalsize
abs_timedelta
date_and_delta
naturaldate
naturalday
naturaldelta
naturaltime
precisedelta
humanize_intword
See humanize documentation for argument details.
To take a more real example, let's take the naturalsize() function. To use it inside a jinja2 template with this extension, you have to use:
The file size is: {{ 30000000|humanize_naturalsize(binary=False, gnu=True) }}
You can use the same logic with all supported functions. If you need other functions, feel free to open a PullRequest.
Installation
pip install jinja2-humanize-extension
Full example
from jinja2 import Template, Environment
# We load the extension in a jinja2 Environment
env = Environment(extensions=["jinja2_humanize_extension.HumanizeExtension"])
template = env.from_string("The file size is : {{ 30000000|humanize_naturalsize() }}")
result = template.render()
# [...]
Project details
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
Close
Hashes for jinja2_humanize_extension-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf8e428c7ae2abd07643af13472c83d10172b3e3951be953d1c2f1c2682072dd |
|
MD5 | 089e2759777f9504c1d9b722bb8c8304 |
|
BLAKE2b-256 | 5addff6196f37ff08ac1001e772731affb9d593916556c06bc215c91be38db09 |
Close
Hashes for jinja2_humanize_extension-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df79433b7f97f79e986502e0d435c0027b7685972c8e6dd94befa0c97f6f045b |
|
MD5 | 42077aaaf82a03d88f70a69a7f8701b7 |
|
BLAKE2b-256 | 361d732515814abd7270e85add43a36d73383b0da2f526943bee1596c2074568 |