python sanic框架cors跨域解决

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)

大功告成了

posted @ 2021-12-03 18:04  BruceLong  阅读(654)  评论(0编辑  收藏  举报