Flask多个Post,@api.route('/')正常,('/analysis/orderstruct')只有key

Moody
  • 1
新手上路,请多包涵

`

import sys
import os

curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
sys.path.append(curPath)
from flask import Flask, request, jsonify
from flask_restplus import Resource, Api
from static.static_const import *
from service.loc_adjust.loc_adjust import LocAdjust, LocAdjustTest
from service.order_structure.data_statistics import *

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
api = Api(app)

@api.route('/')
class LocAdjustApi(Resource):
    def post(self):
        # 获取数据
        data = request.get_data()
        # 返回处理后数据
        la = LocAdjust(data, LOC_ADJUST_NUM, SALES_DIF, ORDER_NUM)
        result = la.main()
        return jsonify(result)

@api.route('/analysis/orderstruct/')
class StructSalesApi(Resource):
    def post(self):
        # 获取数据
        data = request.get_data()
        # 返回处理后数据
        dp = DataProcess(data)
        contain_sku, ex_sku, order_struct = dp.data_parse()
        order_struct, sku_set = dp.dict_df(contain_sku, ex_sku, order_struct)
        if not sku_set:  # 判断是否存在分仓数据
            sku = SkuSales()
        else:
            sku = SkuSalesBin()
        sale_res = sku.data_statistics(order_struct, sku_set)
        return jsonify(sale_res)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=True)

`
la和sale_res 数据结构都是类似`{

"sale_data":
[{
"num_order": "1741",
"sale_onej": "2",
"sale_onep": "449",
"sale_order": "7097",
"sku_id": "A63432"
},
{
"num_order": "67",
"sale_onej": "4",
"sale_onep": "8",
"sale_order": "77",
"sku_id": "A64459"
}]
}` 这样的。
@api.route('/')能请求到数据,能请求到数据,但是@api.route('/analysis/orderstruct')请求到的数据是`
{"sale_data": []}`。有大神能帮我解答下吗,感激不尽!!!

回复
阅读 1.3k
1 个回答
飘雪的浮云
  • 54

你代码里路由写的是

/analysis/orderstruct/

修改一下请求的接口地址试试

宣传栏