创建一个虚拟环境

Linux

python3 -m venv venv

Windows

py -3 -m venv venv

激活虚拟环境

Linux

$ . venv/bin/activate

Windows

> venv\Scripts\activate

关闭虚拟环境

deactivate

Flask设置返回json格式数据

使用标准库json

@app.route('/')
def root():
    t = {
        'a': 1,
        'b': 2,
        'c': [3, 4, 5]
    }
    return json.dumps(t)

Flask获取POST请求

@app.route('/manual_action',methods=['POST'])
def manualSwitchAction():
    if request.method == 'POST':
        switch_name = request.values.get('switchName')
        switch_status = request.values.get('switchStatus')

使用request.values.get()方法

标签: none

评论已关闭