我在Python和sqlite中有一些代码,在执行和打印时会返回正确的数据。但是当我尝试将其传递给HTML时,它会从错误的表中检索数据并将其显示给HTML。 例如,我执行以下python代码:
comments = c.execute('''SELECT * FROM comments''')
conn.commit
for each in comments:
print(each)
newsubs = c.execute('''SELECT * FROM submissions WHERE Signiture = signiture AND Client_ID = client_ID ORDER BY date DESC''')
conn.commit()
print("hello")
var = "hello,!"
return render_template('profile.html', comments = comments, newsubs = newsubs)
然后,我在评论和新闻栏中调用以下HTML代码来显示数据:
{% for y in newsubs %}
<br>
<div id="subcss">
<legend><strong> {{ y[2] }} </strong> {{ y[4] }} <br><br></legend>
{{ y[3] }} <br><br>
<p id = "sig"><strong>Signiture:</strong> {{ y[5] }}</p>
{{ y[1] }} <br><br>
<div id="subcss">
<form action="/comments" method="post">
<textarea name="comment" rows="7" cols="76">Write a comment...</textarea><br>
<input type="submit" value="Submit"><br><br><br>
<button onclick="myFunction()">View Comments</button>
<div id="comdiv">
{% for z in comments %}
<strong>Date:</strong> {{ z[0] }} <br>
<strong>Comment:</strong> {{ z[1] }} <br><br>
{{ z[2] }}
<br>{ z[3] }} {{ z[4] }}
<br>
{% endfor %}
</form><br>
</div>
{% endfor %}
</div>
</div>
问题是从这段代码输出到网页:
{% for z in comments %}
<strong>Date:</strong> {{ z[0] }} <br>
<strong>Comment:</strong> {{ z[1] }} <br><br>
{{ z[2] }}
<br>{ z[3] }} {{ z[4] }}
<br>
{% endfor %}
显示提交表中的数据,而不是评论表。 任何帮助或任何事情都非常感谢。