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

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.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinja2_humanize_extension-0.1.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jinja2_humanize_extension-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for jinja2_humanize_extension-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6bed924dc79c0bffe81035c244267bed6697cbd4fe966631fa9ab3789e3de54d
MD5 f1a985f98f758e821bd89cf415b93e29
BLAKE2b-256 970e8d480557b359f026e415bd7cb8c7cb1c85cedc8e7a5fe45cc36247a084d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jinja2_humanize_extension-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for jinja2_humanize_extension-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4df1e29ebe26e18f52fd1f4f3c9a47cfe82479eec73852510149e4da4b39b03e
MD5 8800e3a0858e866a177e85a333c3d87c
BLAKE2b-256 252a84bd2182d306f18f539a35a524fa911ad1b8c6532aec022a9e961e420bab

See more details on using hashes here.

Supported by

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