防止瓶子在循环中打印新的生产线(Preventing flask from printing new line in a loop)
我正试图在Flash中使用循环产生表格标题,但每次之后都会换行:
{% extends "layout.html" %} {% block title %} Portfolio overview {% endblock %} {% block main %} {% for variable in variables -%} {% for key, value in variable.items() -%} <table> <thead><th>{{ key }}</th></thead> {% endfor -%} {% for key, value in variable.items() -%} <tbody> <td>{{ value }}</td> </tbody> {% endfor -%} {%- endfor -%} </table> <h2>Cash available (US$): {{ cash }}</h2> <h2>Total portfolio value (US$): {{ wealth }}</h2> {% endblock %}结果
不过,我想获得这个期望的结果
I am trying to produce table headings using loop in flash but I get new lines after each:
{% extends "layout.html" %} {% block title %} Portfolio overview {% endblock %} {% block main %} {% for variable in variables -%} {% for key, value in variable.items() -%} <table> <thead><th>{{ key }}</th></thead> {% endfor -%} {% for key, value in variable.items() -%} <tbody> <td>{{ value }}</td> </tbody> {% endfor -%} {%- endfor -%} </table> <h2>Cash available (US$): {{ cash }}</h2> <h2>Total portfolio value (US$): {{ wealth }}</h2> {% endblock %}Result
However, I would like to get this Desired result
最满意答案
给这一个镜头;
{% extends "layout.html" %} {% block title %} Portfolio overview {% endblock %} {% block main %} <table> {% for variable in variables %} <thead> {% for key, value in variable.items() %} <th>{{ key }}</th> {% endfor %} </thead> <tbody> {% for key, value in variable.items() %} <td>{{ value }}</td> {% endfor %} </tbody> {% endfor %} </table> <h2>Cash available (US$): {{ cash }}</h2> <h2>Total portfolio value (US$): {{ wealth }}</h2> {% endblock %}我只是修正了for循环的位置。
Give this a shot;
{% extends "layout.html" %} {% block title %} Portfolio overview {% endblock %} {% block main %} <table> {% for variable in variables %} <thead> {% for key, value in variable.items() %} <th>{{ key }}</th> {% endfor %} </thead> <tbody> {% for key, value in variable.items() %} <td>{{ value }}</td> {% endfor %} </tbody> {% endfor %} </table> <h2>Cash available (US$): {{ cash }}</h2> <h2>Total portfolio value (US$): {{ wealth }}</h2> {% endblock %}I just fixed up the placement of your for loops.
更多推荐
发布评论