如何检查请求POST中是否存在值? [重复]

问题描述 投票:2回答:1

这个问题在这里已有答案:

我使用POST方法提交表单。 Form有一个输入字段:time

我试着检查是否存在参数:

if 'time' in request.data:
   pass

但它不起作用

python python-2.7 flask
1个回答
7
投票

如果您将数据作为常规POST正文查询发布,则应使用request.form,即:

@app.route('/schedule/<int:adv_id>', methods=['POST'])
def schedule(adv_id):
    if "time" in request.form:
        pass  # do whatever you want with it
© www.soinside.com 2019 - 2024. All rights reserved.