1.abort函数
from flask import Flask,abort,request,Response
app = Flask(__name__)
@app.route("/login",methods=["GET","POST"])
def login():
name = request.form.get()
pwd = request.form.get()
#name = ""
#pwd = ""
if name != "zhangsan" or pwd != "admin"
abort(404) #1.传递标准http状态码,400,404,(666就不是标准的)
#2.传递一个参数
#resp = Response("login failed")
#abort(resp)
return "login success!"
if __name__ == "__main__":
app.run(DEBUG=True)
2.自定义异常处理
@app.errorhandler(404)
def error(err):
return "你请求的页面不存在了,请确认后再次访问! 错误信息:%s"%err