book id
和
book title
书名
格式化为按钮,以便我可以在表单提交时使用post方法。当单击按钮时,方法(如下所示)足够好地激发,但是book id没有传递给该方法。我需要
传递给基础方法,因为它将在SQL查询中使用。我有办法做到这一点吗?
{% block body %}
<div class="align-center">
<form action="{{ url_for('books') }}" method="post">
<table class="table">
<thead>
<tr>
<th></th>
<th>Book ID</th>
<th>ISBN #</th>
<th>Title</th>
<th>Author</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6"></td>
</tr>
</tfoot>
{% for book in books %}
<tr>
<td></td>
<td name="bookid">{{ book.id }}</td>
<td name="bookisbn">{{ book.isbn }}</td>
<td name="booktitle"><button btn style="border:none; border-bottom: 1px solid black;">{{ book.title }}</button></td>
<td name="bookauthor">{{ book.author }}</td>
</tr>
{% endfor %}
</table>
</form>
</div>
{% endblock %}
@app.route("/books", methods=["POST"])
@login_required
def books():
bookid = request.form.get("bookid")
return render_template("books.html", message=bookid)