1. 安装 sanic-cors
pip install -U sanic-cors
2. 使用方法
from sanic import Sanic from sanic.response import json from sanic_cors import CORS app = Sanic("Sanic_demo") CORS(app) @app.route('/') async def test(request): ''' 接口请求测试 :param request: :return: ''' return json({'hello-world': '好看的皮囊千篇一律,有趣的灵魂万里挑一'}, ensure_ascii=False) if __name__ == '__main__': app.run(host='0.0.0.0', port=8008, debug=True)
大功告成了