函数示例:
app.py
def index(request):
return web.Response(body=b'<h1>Awesome</h1>')
执行 python3 app.py
,在浏览器中访问时正常应该显示 'Awesome',但是我访问时会 直接下载 当前页面,查看 aiohttp 文档(假装看得懂),Response类声明为 class aiohttp.web.Response(*, status=200, headers=None, content_type=None, body=None, text=None)
,即需要声明 content_type
,于是修改代码:
def index(request):
return web.Response(body=b'<h1>Awesome</h1>', content_type='text/html')
再次访问,一切正常!
(adsbygoogle = window.adsbygoogle || []).push({});