从数据库中获取一些东西,如果方法是get,它只会返回所有内容,但如果它的post,它会返回搜索到的内容,当它的get时,它工作正常,但当它的post时,它会给出正确的值,但html不会“破译”它?
超文本标记语言
{% for account in accounts %}
<tr>
<th scope="col">{{ account["email"] }}</th>
<th scope="col">{{ account["username"] }}</th>
<th scope="col">{{ account["password"] }}</th>
<th scope="col">{{ account["website"] }}</th>
<th></th>
</tr>
{% endfor %}
AJAX
$(document).ready(function () {
$("#search").on("input", function(e) {
$(".table-body").empty();
$.ajax ({
method: "GET",
url: "/manager",
data: {search:$("#search").val()},
})
})
})
Python
@app.route("/manager", methods=["GET", "POST"])
def manager():
loggedUser = session["loggedUser"][0]["username"]
if request.method == "GET":
accounts = db.execute("SELECT * FROM manager WHERE loggedUser = ?", loggedUser)
else:
form = request.form.get("search")
accounts = db.execute("SELECT * FROM manager WHERE loggedUser = ? AND website LIKE ?", loggedUser, form + "%")
print(accounts)
return render_template("manager.html", accounts=accounts)
它给出了正确的结果,但它不会在html中给出,除非它是get方法
POST时输出
[{'id': 1, 'loggedUser': 'Hyde', 'username': None, 'email': None, 'password': '123', 'website': 'HydPass'}]
结构
CREATE TABLE manager (id INTEGER, loggedUser TEXT NOT NULL, username, email, password TEXT NOT NULL, website TEXT NOT NULL, PRIMARY KEY (id));
1条答案
按热度按时间7d7tgy0s1#
结果我不得不用 AJAX 来更新
AJAX