Skip to main content

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

jinja2_humanize_extension-0.2.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

jinja2_humanize_extension-0.2.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for jinja2_humanize_extension-0.2.2.tar.gz
Algorithm Hash digest
SHA256 fda7b515f89757515b3a05d5b874272ea83939ff9a5cb02e4aae3c9d35843a63
MD5 1ae4c1ea30e53e8c0f3d62d88aec5f0f
BLAKE2b-256 24634bca2a5af5d2900a1bf9cf6c30a4010924959aede3a3e13524a0b259d3fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jinja2_humanize_extension-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b5cf37f8127bfcb22a133d277fd79607e397abbedd4f51d604c5449a7753e0b0
MD5 c965aeec059c98862161c9c8b646c0b7
BLAKE2b-256 9e55969305284cd7abb0431423890b8c04ef4e2c640f7d840e5a230ed9d30be8

See more details on using hashes here.

Supported by

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