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
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.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bed924dc79c0bffe81035c244267bed6697cbd4fe966631fa9ab3789e3de54d |
|
MD5 | f1a985f98f758e821bd89cf415b93e29 |
|
BLAKE2b-256 | 970e8d480557b359f026e415bd7cb8c7cb1c85cedc8e7a5fe45cc36247a084d9 |
Close
Hashes for jinja2_humanize_extension-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4df1e29ebe26e18f52fd1f4f3c9a47cfe82479eec73852510149e4da4b39b03e |
|
MD5 | 8800e3a0858e866a177e85a333c3d87c |
|
BLAKE2b-256 | 252a84bd2182d306f18f539a35a524fa911ad1b8c6532aec022a9e961e420bab |