2020年9月17日 01:34 by wst
web开发包含内容:
1. 返回html给前端;
2. 使用蓝图分解路由;
3. 蓝图和单函数的混用;
from sanic import Sanic
from sanic import Blueprint
from sanic.response import html
app = Sanic(__name__)
async def hello(request):
return html("<h1>Hello</h1>")
async def age(request):
return html("<h1>age:20</h1>")
# 路由名称及前缀配置
bp = Blueprint('demo', url_prefix='demo')
bp.add_route(hello, "/hello", methods=['GET'])
app.blueprint(bp)
app.add_route(age, "/age", methods=['GET'])
# 启动服务
app.run(host="0.0.0.0", port=8000, debug=True)