我正在努力完成我的最终项目 . 我需要加入2个表"book"和"idlist"并执行index.html中的值 . 这是python和html代码(也是idlist Table book Table) . 如果有人知道哪里出错,我将不胜感激!
@app.route("/", methods=["GET", "POST"])
@login_required
def index():
"""Show reading list"""
if request.method == "GET":
# Execute list joining "book" and "idlist" tables
list = db.execute("SELECT Title1, Status, LastUpdate, Author, Year, Country, Language FROM idlist INNER JOIN book on idlist.Title1=book.Title WHERE id=:id",
id=session["user_id"])
# If the user has no list yet
if not list:
el = {'Title1': "No", 'Author': "No", 'Year': "No", 'Country': "No", 'Language': "No", 'Status': "No", 'LastUpdate': "No"}
return render_template("index.html")
else:
return render_template("index.html")
return render_template("index.html")
html应该从连接表中执行值
{% extends "layout.html" %}
{% block title %}
Index
{% endblock %}
{% block main %}
<table style="width:100%">
<tr>
<th>Title</th>
<th>Author</th>
<th>Year</th>
<th>Country</th>
<th>Language</th>
<th>Status</th>
<th>Last update</th>
</tr>
{% for el in list %}
<tr>
<td>
{{ el.Title1 }}
</td>
<td>
{{ el.Author }}
</td>
<td>
{{ el.Year }}
</td>
<td>
{{ el.Country }}
</td>
<td>
{{ el.Language }}
</td>
<td>
{{ el.Status }}
</td>
<td>
{{ el.LastUpdate }}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
当我使用用户ID 16登录时出现错误:RuntimeError:near“update”:语法错误[SQL:'SELECT Title,Status,update,Author,Year,Country,Language FROM idlist INNER JOIN book on idlis t.Title = book.Title WHERE id = 16']