python - 如何通过jinja2中另一个列表中的项目数重复列表项目
问题描述
我有 2 个列表、表格和列。我需要按列名的数量重复表名,但不包括第一个。
这是参数的一个例子
PARAMS = {'tables': ["table1",
"table2"],
'columns': ["col1",
"col2",
"col3"]
}
这是我尝试过的语法:
QUERY_TEMPLATE = """
{% for table in tables %}
{{table | sqlsafe}}_{% for col in columns %}{% if not loop.first %}{{col | sqlsafe}}()
{% if not loop.last %},{% endif %}{% endif %}{%- endfor %}{%- endfor %}
"""
上面的语法给了我这个输出
table1_col2()
,col3()
table2_col2()
,col3()
但这是所需的输出
table1_col2(),
table1_col3(),
table2_col2(),
table2_col3(),
编辑:我正在使用一个名为jinjasql
过滤| sqlsafe
器的python库
解决方案
推荐阅读
- android - android exoplayer 未正确安装且未跨设备拉伸
- sql-server - 限制 Windows 身份验证以访问 SQL Server 数据库
- .htaccess - 为标签重定向 301 不起作用。怎么弄?
- java - 如何在 Unirest 中将响应正文作为 InputStream 接收?
- tabulator - 为每个单元格制作自定义工具提示
- javascript - 返回续集中行的自定义值?
- react-native - 如何从数组中为 AsyncSelect 设置样式边框颜色 - ReactNative?
- vue.js - 在 vue-cli3 中为构建文件提供静态文件名
- regex - 即使您不在正确的组中,Perl 正则表达式分组结果也会添加额外的字符
- python - 运行成本 sigmoid 成本函数时出错