【发布时间】:2018-10-13 04:15:17
【问题描述】:
在我的 application.py 中,我正在执行查询并在呈现 html 模板时发送结果 rows:
rows = db.execute("SELECT * FROM fase1 JOIN gamesf1 ON fase1.f1game_id = gamesf1.f1game_id WHERE user_id = :userid AND fase1.f1game_id = :f1gameid",
userid=request.args.get("u"), f1gameid=request.args.get("g"))
return render_template("updatef1.html", rows=rows)`
在我的 html 文件中,我可以使用 rows 中的变量,如下所示并使用它们制作表单:
{% for row in rows %}
<h2>{{(row["f1game_team1"])}} vs. {{(row["f1game_team2"])}}</h2>
<form action="/f1updated" id="f1update" method="post">
<input type="number" class="form-control" id="marcadort1" name="marcadort1" value={{(row["marcador_t1"])}} min="0">
...
</form>
{% endfor %}
而且效果很好。
我遇到的问题是在同一个 for 循环中编写脚本 function() 时:
<script>
let form = document.getElementById("f1update");
form.onsubmit = function() {
if (form.marcadort1.value == 0 & form.marcadort2.value == 0 & form.primergol.value != "No Goles")
{
alert("Si no hay goles, no puedes tener un pais en PRIMER GOL");
return false;
}
if (form.marcadort1.value == 0 & form.primergol.value == {{(row["f1game_team1"}}))
{
alert("No puedes poner PRIMER GOL al pais que tenga marcado 0");
return false;
}
};
</script>
第一个 if 工作正常,因为我没有使用任何变量。但是第二个 if 使用变量 {{(row["f1game_team1"}} 并给我一个 Parsing error: Unexpected token {
关于如何在函数脚本中使用这些变量有任何帮助吗?
谢谢!
【问题讨论】:
标签: python html scripting jinja2