aiohttp.web的mako模板呈现程序(用于asyncio的http服务器)
aiohttp_mako的Python项目详细描述
mako基于aiohttp_jinja2的aiohttp.web模板呈现程序。图书馆 具有几乎相同的api并支持python 3.5(PEP492)语法。它用于aiohttp_debugtoolbar。
示例
importasyncioimportaiohttp_makofromaiohttpimportweb@aiohttp_mako.template('index.html')asyncdeffunc(request):return{'head':'aiohttp_mako','text':'Hello World!'}asyncdefinit(loop):app=web.Application(loop=loop)lookup=aiohttp_mako.setup(app,input_encoding='utf-8',output_encoding='utf-8',default_filters=['decode.utf8'])template="""<html><body><h1>${head}</h1>${text}</body></html>"""lookup.put_string('index.html',template)app.router.add_route('GET','/',func)handler=app.make_handler()srv=awaitloop.create_server(handler,'127.0.0.1',8080)print("Server started at http://127.0.0.1:8080")returnsrv,handlerloop=asyncio.get_event_loop()srv,handler=loop.run_until_complete(init(loop))try:loop.run_forever()exceptKeyboardInterrupt:loop.run_until_complete(handler.finish_connections())
许可证
aiohttp_mako是在apache 2许可下提供的。