步骤一: 见下图, 在前端项目下, 执行命令: npm install mockjs
步骤二:
python3执行mockjs 代码如下:
def get_response(self, template_response): js_function = """ function get_json(json_template){ var Mock = require('mockjs') var data = Mock.mock(json_template) return JSON.parse(JSON.stringify(data)) } """ ctx = execjs.compile(js_function) data_json = ctx.call('get_json', template_response) return data_json