Jinja2 Padding and Aligning Strings

Viewed 8707

I would like to achieve something similar to this (https://pyformat.info/#string_pad_align) in Jinja2.

In python if I want a string to always be a certain length I would do something like this:

'{:>10}'.format('test')

How can I do this in Jinja2?

2 Answers

From jinja2 documentation

In most cases it should be more convenient and efficient to use the % operator or str.format().

So you can always write

{{ "{:>10}".format("test") }}

so as to keep the modern format string syntax, which is usually feature-richer than the printf-style formatting from the other answer.

Related