Steven最近因为工作需要,在学习Sanic,上网搜索之后发现, 针对于Sanic的资料相对比较少,所以想要快速上手还是有一定的困难的。输出最简单的Hello world可以说是手到擒来
from sani import Sanic,response
app = Sanic()
@app.route('/')
async def rindex(request): #每一个函数里面必备的参数就是request参数
return response.json({'Hello':"World"})
if __name__ == "__main__":
app.run('127.0.0.1',8009,debug=True,worker=4)
那么如何把我们能够快速向其他模板一样,输出HTML文件呢? 比较HTML 是客户与我们交互的关键所在
首先,我们在py文件同级目录下面创建一个templates 文件,然后在里面创建一个index.html文件
<html>
<head>
</head>
<body>
<table style="border:1px solid gray;padding:0 0 5px;">
{%for d in data%}
<tr>
<td>{
{d.name}}</td>
<td>{
{d.age}}</td>
</tr>
{%endfor%}
</table>
</bo