一个测试http与post的flask demo

用于测试http请求,作为例子

flask demo

from flask import Flask, session, request, Request, make_response

app = Flask(__name__)
request: Request
app.secret_key = "key"


@app.route("/request", methods=['POST', 'GET'])
def hello():
    query = request.args
    post = request.form
    return f"query: {query}\n" \
           f"post: {post}"


@app.route("/session")
def session_handle():
    for k, v in request.args.items():
        session[k] = v
    resp = make_response({k: v for k, v in session.items()})
    for k, v in request.args.items():
        resp.set_cookie(f"cookie_{k}", v)
    return resp

运行命令

export FLASK_APP=demo.py
flask run


这是在win10环境下运行:pyCharm 命令窗口:flask框架执行

image
不是在根目录的项目需要增加路径
export FLASK_APP=xxxxxx/demo.py
flask run
image