from flask import Flask
from flask_restful import Api, Resource, reqparse
parser = reqparse.RequestParser(trim=True)
parser.add_argument('name', location=['json', 'args'])
parser.add_argument('name', location=['json', 'args'],type=dict)#可以接收复合型的json参数
parser2 = reqparse.RequestParser()
parser2.add_argument('age', location=['json', 'args'])
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
args = parser.parse_args()
args2 = parser2.parse_args()
print args['name']
return {'name': args['name'], 'age': args2['age']}
def post(self):
args = parser.parse_args()
args2 = parser2.parse_args()
print args['name']
return {'name': args['name'], 'age': args2['age']}
api.add_resource(HelloWorld, '/p')
if __name__ == '__main__':
app.run(debug=True)
原地址:https://blog.csdn.net/u010445540/article/details/52861197?utm_source=blogxgwz4