【发布时间】:2017-09-24 07:32:24
【问题描述】:
我正在尝试 SQLite 和烧瓶,我已经完成了添加条目并显示了所有内容。现在我被困在我的删除功能上。所以我想我会尝试寻求帮助。这是我的算法:
@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>
谁能告诉我哪里做错了?我想不通。这很容易,但我不明白为什么我没有找到。我的本地主机上的错误。任何帮助,将不胜感激。我无处可去。
【问题讨论】: