我试过了
list1 = [{"username": "abhi", "pass": 2087}]
return render_template("file_output.html", list1=list1)
Run Code Online (Sandbox Code Playgroud)
在模板中
<table border=2>
<tr>
<td>
Key
</td>
<td>
Value
</td>
</tr>
{% for dictionary in list1 %}
{% for key in dictionary %}
<tr>
<td>
<h3>{{ key }}</h3>
</td>
<td>
<h3>{{ dictionary[key] }}</h3>
</td>
</tr>
{% endfor %}
{% endfor %}
</table>
Run Code Online (Sandbox Code Playgroud)
上面的代码将每个元素分成多个
核心价值 [
{
"
ü
小号
e ...
我在一个简单的python脚本中测试了上面的嵌套循环,它工作正常,但不是在jinja模板中.
有时,我们的表需要将多个列附加在一起以形成唯一键。这可以通过执行以下操作来完成:
select
*,
col1 || "_" || col2 as unique_key
from
my_table
Run Code Online (Sandbox Code Playgroud)
这种方法有效,但导致多个分析师之间缺乏统一性。
我想利用 python *args(我认为 jinja2 使用varargs)功能来制作一个宏,它可以接受任意数量的参数并在所有参数之间创建一个唯一的键。
理想结果:
select
*,
unique_key(col1, col1, ..., colN)
from
my_table
Run Code Online (Sandbox Code Playgroud) jinja2 ×2
dbt ×1
dictionary ×1
flask ×1
iteration ×1
python ×1
snowflake-cloud-data-platform ×1
sql ×1