Python的web框架sanic

Python 3.5+ web server that’s written to go fast

前段时间发现了一个新的Python web框架,看到Benchmarks有点心动,决定上手实验一波

Python的web框架sanic_第1张图片

from sanic import Sanic
from sanic.response import html

from jinja2 import Environment, PackageLoader

env = Environment(loader=PackageLoader('app', 'templates'))

app = Sanic(__name__)

@app.route('/')
async def test(request):
    data = {'name': 'Hello world!'}

    template = env.get_template('index.html')
    html_content = template.render(name=data["name"])
    return html(html_content)

app.run(host="127.0.0.1", port=8000)

文件目录


Python的web框架sanic_第2张图片

Python的web框架sanic_第3张图片

你可能感兴趣的:(python,Python笔记)