1
我試着用燒瓶SQLite,我已經添加了條目並顯示出來。現在我卡在我的刪除功能。所以我想通了,我會試着尋求幫助。這裏是我的算法:燒瓶SQLite SQalchemy通過ID號刪除條目
@app.route('/deleted', methods = ['GET', 'POST'])
def deleted():
if request.method == 'POST':
if not request.form['id']:
flash('Please enter the right number!','error')
else:
student1 = Students(request.form['id'])
x = Students.query.filter_by(id=student1)
db.session.delete(x)
db.session.commit()
flash('Record was deleted successfully ')
return redirect(url_for('show_all'))
return render_template('deleted.html')
這是我的HTML:
<!DOCTYPE html>
<html>
<body>
<h3>S Kickout the student</h3>
<hr/>
{%- for category, message in get_flashed_messages(with_categories = true) %}
<div class = "alert alert-danger">
{{ message }}
</div>
{%- endfor %}
<form action = "/deleted/{{id}}" method = "post">
<label for = "id">Id Number</label><br>
<input type = "text" name = "id" placeholder = "Student Id" /><br>
<input type = "submit" value = "Delete" />
</form>
</body>
</html>
有誰能夠告訴我哪裏做錯了?我無法弄清楚。這很容易,但我不會明白爲什麼我會找不到。我的本地主機上出現錯誤。任何幫助,將不勝感激。我無處可去。由於該方法是POST和形式存儲id
,你可以用request.form['id']
訪問
<form action = "/deleted" method = "post">
: