Python Flask SQLite SQalchemy通过ID号删除条目
我正在试用SQLite和flask,我已经添加了条目并展示了所有内容。现在我被我的删除功能卡住了。所以我想我应该试着寻求帮助。这是我的算法:Python Flask SQLite SQalchemy通过ID号删除条目,python,sqlite,flask,Python,Sqlite,Flask,我正在试用SQLite和flask,我已经添加了条目并展示了所有内容。现在我被我的删除功能卡住了。所以我想我应该试着寻求帮助。这是我的算法: @app.route('/deleted', methods = ['GET', 'POST']) def deleted(): if request.method == 'POST': if not request.form['id']: flash('Please enter the right num
@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>
让我们把学生踢出去
{%-对于类别,get_Flash_消息中的消息(其中_categories=true)%}
{{message}}
{%-endfor%}
身份证号码
谁能告诉我哪里做错了?我想不出来。这很容易,但我不明白为什么我找不到一个。在我的本地主机上出错。任何帮助都将不胜感激。我一事无成。您可以通过从模板中的操作中删除
id
来解决此问题:
<form action = "/deleted" method = "post">
由于该方法是POST,并且表单存储了
id
,因此可以通过请求访问该方法。表单['id']
可以通过从模板中的操作中删除id
来解决此问题:
<form action = "/deleted" method = "post">
由于该方法是POST,并且表单存储了id
,因此可以通过request.form['id']
访问它