一切运行良好,API(flask)很好地返回数据。然而,当我尝试自定义响应代码时,我无法做到。
以下是我尝试的两种方式:
from flask import make_response
dictionary = {1:'a', 2:'b'}
resp = make_response(dictionary,1001)
return resp
#In developer tools, I could see the data, but status-code is 200
.
from flask import Response
dictionary = {1:'a', 2:'b'}
resp = Response(dictionary, status = 1001)
return resp
#Here again, I see the data, but the status code is 200
我该如何将状态码设置为其他数值?
return Response("{1:'a', 2:'b'}", status=201, mimetype='application/json')
顺便说一下,1001
不是有效的HTTP状态码。 - T.M Luan