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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4243d738b05ebf19460ef4a8b13a319edf52b8339b9e33b6a0573f7ae83d7d3 |
|
MD5 | 39f176dd4cbb327b52af528f40c948ef |
|
BLAKE2b-256 | 18e49e3da847ac472e005c0509d472ad88e6c8903eaa698c123c5c46360d682b |
Close
Hashes for jinja2_humanize_extension-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19ec9f85104d6f29b8b4215930ad21674b361c9931476bf51e246d247a1f8571 |
|
MD5 | b04f9a2b973623aea57ec4f330bbd309 |
|
BLAKE2b-256 | 3cf66b68555413291a8eb4277b9d5c8c948d83ac90051e3942c7e26608bc6aad |