美文网首页
Flask http methods

Flask http methods

作者: candice0430 | 来源:发表于2022-09-07 19:18 被阅读0次

接口的请求方式有很多种:Get、Post、Put、Delete等
那么自己设计的接口要支持哪些请求方式呢?以及同一个接口,不同的请求方式要做的事是否相同呢?我们如何区分?

1.同时支持多种请求方式

bp = Blueprint('user', __name__, url_prefix='/user')


@bp.route('/login', methods=["GET", "POST"])
def login():
    if request.method == 'GET':
        return render_template("login.html")
    else:
        login_form = LoginForm(request.form)
        if login_form.validate():
            print("验证通过")
            return redirect("/")
        else:
            print("验证失败", login_form.errors)
            flash("邮箱或密码不正确")
            return redirect(url_for("user.login"))

2.默认支持方式:Get

@bp.route('/logout')
def logout():
    session.clear()
    return redirect(url_for("user.login"))

3.还可以将不同方法的视图分成不同的功能

@app.get('/login')
def login_get():
    return show_the_login_form()

@app.post('/login')
def login_post():
    return do_the_login()</pre>

相关文章

  • Flask http methods

    接口的请求方式有很多种:Get、Post、Put、Delete等那么自己设计的接口要支持哪些请求方式呢?以及同一个...

  • 2018-05-29 Allowed methods have

    Flask 如果上面的methods只写了methods=('POST')就会爆出如上错误,记得加上逗号,让传进去...

  • HTTP—常用methods

    想让服务器知道我们请求的意图,那就须清楚HTTP中常用 methods(请求方法),先来列一列有哪些methods...

  • HTTP: Request methods

    HTTP 定义了一组请求方法, 以表明要对给定资源执行的操作。 GET GET方法请求一个指定资源的表示形式. 使...

  • http: request methods

    request methods get, post, delete, put, 以及其他5个

  • flask web development pdf

    http://flask.pocoo.org/docs/0.10/.latex/Flask.pdf

  • DFP-ResUNet:Convolutional Neural

    论文:Computer Methods and Programs in Biomedicine 2020[http...

  • Flask扩展-学习

    Flask扩展详细说明文档 http://flask.pocoo.org/extensions/ Flask表单w...

  • http

    http http.METHODS 解析器支持的 HTTP 方法列表 http.STATUS_CODES 所有标准...

  • axios 发送数据

    methods:{ update:function(){ axios.post('http://localhost...

网友评论

      本文标题:Flask http methods

      本文链接:https://www.haomeiwen.com/subject/ydwgnrtx.html