[英]customize the method not allow response in flask
在Flask Framework中,定义一条路线
@main.route('/')
def index():
return render_template('index.html')
您只能使用get方法来请求index.html。 如果我尝试将一些数据发布到index.html。 我有一种不允许网页返回的方法。 没错
但是我的问题是,我仍然可以自己定制页面吗? 例如,返回json数据,而不是不允许使用网页的方法?
您可以创建错误处理程序
from flask import jsonify
@app.errorhandler(405)
def method_not_allowed(e):
return jsonify({'error': 405}), 405
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.