如何使用Flask处理GET查询字符串 [英] How to process GET Query String with Flask

查看:53
本文介绍了如何使用Flask处理GET查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Flask处理较长的GET请求?是否可以获取所有参数的字典?

How do I process a long GET request with Flask? Is is possible to get a dictionary all the params?

这是我要解析的查询字符串:

Here is the query string I'm trying to parse:

/?msisdn=19150000001&to=12108054321&messageId=000000FFFB0356D1&text=This+is+an+inbound+message &type=text&message-timestamp=2012-08-19+20%3A38%3A23

这是到目前为止我只获得'msisdn'值的代码:

And Here is the code I have to far which only gets the 'msisdn' value:

import os
from flask import Flask
from flask import request
from flask import jsonify

app = Flask(__name__)

@app.route('/', methods=['GET'])
    def hello():
        if request.method == 'GET':
            json = request.args.getlist('msisdn')
            return str(json)
        else:
            return 'Hello World!'

推荐答案

是. request.args MultiDict :

from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/")
def hello():
    all_args = request.args.lists()
    return jsonify(all_args)

这篇关于如何使用Flask处理GET查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆