APo*_*031 4 python string formatting jinja2
我想在Jinja2中实现与此类似的功能(https://pyformat.info/#string_pad_align).
在python中如果我想要一个字符串总是一定长度我会做这样的事情:
'{:>10}'.format('test')
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Jinja2中做到这一点?
我找到了解决方案!您可以像使用Jinja的内置过滤器一样使用
{{ "%-10s" | format("test",) }}
Run Code Online (Sandbox Code Playgroud)