美文网首页
flask框架获取前端POST上来的JSON数据

flask框架获取前端POST上来的JSON数据

作者: MccReeee | 来源:发表于2017-06-01 09:41 被阅读4755次

    request.get_data()拿到字符串数据
    再用json.loads序列化一下

    具体代码见下

    # -*- coding:utf-8 -*-
    from flask import Flask, request
    import json
    
    
    def after_request(response):
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = 'PUT,GET,POST,DELETE'
        response.headers['Access-Control-Allow-Headers'] = 'Content-Type,Authorization'
        return response
    
    
    def create_app():
        app = Flask(__name__)
        app.after_request(after_request)
    
    
        @app.route("/add_Spec",methods=['POST'])
        def add_Spec():
            print '新增规格'
            data = request.get_data()
            json_re = json.loads(data)
            print json_re
            return 'json_re'
    

    相关文章

      网友评论

          本文标题:flask框架获取前端POST上来的JSON数据

          本文链接:https://www.haomeiwen.com/subject/yypsfxtx.html