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 {% raw %}{{ 'VALUE'|humanize_{humanize_fn}([humanize_fn_args]) }}{% endraw %}.

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: {% raw %}{{ 30000000|humanize_naturalsize(binary=False, gnu=True) }}{% endraw %}

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 : {% raw %}{{ 30000000|humanize_naturalsize() }}{% endraw %}")
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.0.tar.gz (3.2 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.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jinja2_humanize_extension-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 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.0.tar.gz
Algorithm Hash digest
SHA256 75637507baac9d102903032e49c8e325f3917036fa7e899ab46d1eecb87ed89d
MD5 d6dca639516f36531465b9252b48019f
BLAKE2b-256 3e85012fd77ed30922aca82fc73e4fa64a5af5591a9ca00f9c30e83874846187

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jinja2_humanize_extension-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67dcac5886869e71671588f62f26e37f35843e2c0fce30ef4e943c76f04c38db
MD5 3d9a183831b62348234a2b2d4a5adb77
BLAKE2b-256 878783b8e864f9b8de41f5ed333e91dae5c44a942413454e2765ef989457f0f9

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