Flask 基础组件:请求和响应

Posted qiu-hua

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask 基础组件:请求和响应相关的知识,希望对你有一定的参考价值。

from flask import Flask
    from flask import request
    from flask import render_template
    from flask import redirect
    from flask import make_response

    app = Flask(__name__)


    @app.route(/login.html, methods=[GET, "POST"])
    def login():

        # 请求相关信息
        # request.method
        # request.args
        # request.form
        # request.values
        # request.cookies
        # request.headers
        # request.path
        # request.full_path
        # request.script_root
        # request.url
        # request.base_url
        # request.url_root
        # request.host_url
        # request.host
        # request.files
        # obj = request.files[‘the_file_name‘]
        # obj.save(‘/var/www/uploads/‘ + secure_filename(f.filename))

        # 响应相关信息
        # return "字符串"
        # return render_template(‘html模板路径‘,**{})
        # return redirect(‘/index.html‘)

        # response = make_response(render_template(‘index.html‘))
        # response是flask.wrappers.Response类型
        # response.delete_cookie(‘key‘)
        # response.set_cookie(‘key‘, ‘value‘)
        # response.headers[‘X-Something‘] = ‘A value‘
        # return response


        return "内容"

    if __name__ == __main__:
        app.run()

 

以上是关于Flask 基础组件:请求和响应的主要内容,如果未能解决你的问题,请参考以下文章

Flask基础

flask基础之Response响应对象

flask基础之请求处理核心机制

Flask框架基础功能

Flask 基础组件:Session

flask入门