flask_restful.abort = api_abort
def api_abort( httpcode=400, errcode=None, message=None, key=""):
res = BaseResponse()
res.errcode = errcode or 4011
if message:
res.errmsg = message
else:
res.errmsg = key + codetype.get(res.errcode)
res.dict.pop('data')
if httpcode == 200:
print(123456, res.dict)
return jsonify(res.dict), httpcode
return abort( httpcode, **res.dict)
@app.after_request
def after_request(response):
# 允许跨域
response.headers.add('Access-Control-Allow-Origin', '*')
if request.method == 'OPTIONS':
response.headers['Access-Control-Allow-Methods'] = 'POST, DELETE, PUT, GET'
headers = request.headers.get('Access-Control-Request-Headers')
if headers:
response.headers['Access-Control-Allow-Headers'] = headers
return response
当 return abort( httpcode, **res.dict) 状态码 400 提示跨域
1
viakiba 2019-07-06 14:28:19 +08:00 via Android
加 header
|
3
Acebiu 2019-07-06 14:47:00 +08:00
|
4
Acebiu 2019-07-06 14:48:51 +08:00
打扰了,不小心看成 CORS 了...
|
5
ropon OP 感觉不是跨域的问题,迷芒了。
https://i.bmp.ovh/imgs/2019/07/c22bfb001a8c595a.jpg |