Skip to main content

a jinja2 extension to use humanize library inside jinja2 templates

Project description

jinja2_humanize_extension

Status (master branch)

GitHub CI Maintenance

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!)

logo

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

jinja2_humanize_extension-0.4.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file jinja2_humanize_extension-0.4.0.tar.gz.

File metadata

File hashes

Hashes for jinja2_humanize_extension-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e7d69b1c20f32815bbec722330ee8af14b1287bb1c2b0afa590dbf031cadeaa0
MD5 183beafb49887ad7ba632707407870d7
BLAKE2b-256 74770bba383819dd4e67566487c11c49479ced87e77c3285d8e7f7a3401cf882

See more details on using hashes here.

File details

Details for the file jinja2_humanize_extension-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jinja2_humanize_extension-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6326e2da0f7d425338bebf58848e830421defbce785f12ae812e65128518156
MD5 7f5cf59c0d32a97b8f63ee5b4ee271c9
BLAKE2b-256 26b408c9d297edd5e1182506edecccbb88a92e1122a057953068cadac420ca5d

See more details on using hashes here.

Supported by

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