from sanic.response import text
@app.route("/")asyncdefhandler(request):return text("Hi 😎")
响应类型: text/html; charset=utf-8
响应说明: 返回 HTML 文档
from sanic.response import html
@app.route("/")asyncdefhandler(request):return html('<!DOCTYPE html><html lang="en"><meta charset="UTF-8"><div>Hi 😎</div>')
响应类型: application/json
响应说明: 返回 JSON 内容
from sanic.response import json
@app.route("/")asyncdefhandler(request):return json({"foo":"bar"})