Python 以最聪明的方式将用户返回到烧瓶中的推荐人
我想删除一些东西,所以我使用了一个帖子,但是我想让用户返回视图-url实际上根据用户的不同而不同,所以我希望能够发送回推荐人,但我不认为这样做是明智的 这是我的密码:Python 以最聪明的方式将用户返回到烧瓶中的推荐人,python,flask,Python,Flask,我想删除一些东西,所以我使用了一个帖子,但是我想让用户返回视图-url实际上根据用户的不同而不同,所以我希望能够发送回推荐人,但我不认为这样做是明智的 这是我的密码: @app.route('/delete', methods=['POST']) def delete(): if request.method == 'POST': _id = request.form.get('_id') mongo.db.xxx.remove({'_id': _id})
@app.route('/delete', methods=['POST'])
def delete():
if request.method == 'POST':
_id = request.form.get('_id')
mongo.db.xxx.remove({'_id': _id})
return request.referrer
else:
return request.referrer
做这件事的经典优雅方式是什么。我是否必须使用session,或者是否有其他方法可以使用flask来执行此操作。在为delete视图呈现表单时,可以添加一个名为
next
的隐藏表单元素:
<form ...>
<input type="hidden" name="next" value="{{ request.path }}">
...
</form>
注意:重定向处理应注意防止下一个参数成为指向任意站点的绝对URL(请参阅)
...
return redirect(request.form.get('next', '/'))