a jinja2 extension to use humanize library inside jinja2 templates
Project description
jinja2_humanize_extension
Status (master branch)
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
(deprecated with humanize >= 4.0, we keep it for compatibility)date_and_delta
(deprecated with humanize >= 4.0, we keep it for compatibility)naturaldate
naturalday
naturaldelta
naturaltime
precisedelta
ordinal
intcomma
intword
apnumber
fractional
scientific
clamp
metric
activate
deactivate
thousands_separator
decimal_separator
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) }}
result content will be : The file size is : 30.0 MB
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()
# [...]
result content will be : The file size is : 30.0 MB
Contributing guide
See CONTRIBUTING.md file.
Code of Conduct
See CODE_OF_CONDUCT.md file.
Sponsors
(If you are officially paid to work on MetWork Framework, please contact us to add your company logo here!)
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
File details
Details for the file jinja2_humanize_extension-0.4.0.tar.gz
.
File metadata
- Download URL: jinja2_humanize_extension-0.4.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7d69b1c20f32815bbec722330ee8af14b1287bb1c2b0afa590dbf031cadeaa0 |
|
MD5 | 183beafb49887ad7ba632707407870d7 |
|
BLAKE2b-256 | 74770bba383819dd4e67566487c11c49479ced87e77c3285d8e7f7a3401cf882 |
File details
Details for the file jinja2_humanize_extension-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: jinja2_humanize_extension-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6326e2da0f7d425338bebf58848e830421defbce785f12ae812e65128518156 |
|
MD5 | 7f5cf59c0d32a97b8f63ee5b4ee271c9 |
|
BLAKE2b-256 | 26b408c9d297edd5e1182506edecccbb88a92e1122a057953068cadac420ca5d |