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

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数据)