代码 用 django 做的测试代码
我不需要 test 接口的返回结果,直接返回前端数据 除了异步处理还有没有其他的方法?
def startPage(request):
try:
data = {'start':func.now_time()}
test()
data['end'] = func.now_time()
return HttpResponse(func.visitSuccess(data=data))
except:
return HttpResponse(func.visitFail())
def test():
print(func.now_time())
time.sleep(10)
print(func.now_time())
postman 返回结果
{
"code": 200,
"msg": "成功",
"data": {
"start": "2018-11-09 09:42:58",
"end": "2018-11-09 09:43:08"
}}
我不需要 test 接口的返回结果,直接返回前端数据 除了异步处理还有没有其他的方法?
def startPage(request):
try:
data = {'start':func.now_time()}
test()
data['end'] = func.now_time()
return HttpResponse(func.visitSuccess(data=data))
except:
return HttpResponse(func.visitFail())
def test():
print(func.now_time())
time.sleep(10)
print(func.now_time())
postman 返回结果
{
"code": 200,
"msg": "成功",
"data": {
"start": "2018-11-09 09:42:58",
"end": "2018-11-09 09:43:08"
}}