【发布时间】:2022-02-02 14:06:01
【问题描述】:
所以,我刚刚学习了用烧瓶制作一些网站。一切都很好,直到这个错误让我发疯。你能解决我的问题吗?
这是我删除一些笔记的 def 函数
@views.route('/delete-note',methods=['POST'])
def delete_note():
note = json.loads(request.data)
noteId = note['noteId']
note = Note.query.get(noteId)
if note:
if note.user_id == current_user.id:
db.session.delete(noteId)
db.session.commit()
return jsonify({})
这是我的 .js 代码
function deleteNote(noteId) {
fetch("/delete-note", {
method: "POST",
body: JSON.stringify({ noteId: noteId }),
}).then((_res) => {
window.location.href = "/";
});
}
这就是我用html制作按钮的方式
<ul class="list-group list-group-flush" id="notes">
{% for note in user.notes %}
<li class="list-group-item">
{{ note.data }}
<button type="button" class="close" onClick="deleteNote({{ note.id }})">
<span aria-hidden="true">×</span>
</button>
</li>
{% endfor %}
</ul>
你能帮帮我吗?我不知道如何解决它。请帮帮我
【问题讨论】:
-
你加载的js文件是否正确。您可以尝试在 HTML 标记之前加载该函数,例如
标签: javascript python html