Jinja有一个“中心".格式选项,但是“右对齐"如何? [英] Jinja has a "center" formatting option, but how about "right align"?

查看:58
本文介绍了Jinja有一个“中心".格式选项,但是“右对齐"如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有

{% for key,value in adict %}
{{key}}:{{value}}
{% endfor %}

如何确保填充所有键,以便输出为

How do I ensure that all of the keys are padded such that the output is

     something: 1
someotherthing: 3
  thelastthing: 2

这不是我正在处理的网页,不是,我只是获得用于打印的字符串输出.

edit: This is not a webpage I am working on, I am just getting string output for printing.

推荐答案

{{ key.rjust(20) }}:{{value}}起到了作用

我不知道您可以只从框中调用python字符串命令.如果有人使用管道有更多的"jinja"解决方案,我将给出答案.

I did not know you could just call python string commands from the box. If someone has a more "jinja" solution, using pipes, I will give the answer to that.

这篇关于Jinja有一个“中心".格式选项,但是“右对齐"如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆