Jinja2对Bareasgi的支持
bareasgi-jinja2的Python项目详细描述
Bareasgi-Jinja2
jinja2支持bareASGI(阅读documentation)
用法
试试下面的。
fromtypingimportMapping,Anyimportjinja2importos.pathimportuvicornfrombareasgiimportApplicationimportbareasgi_jinja2here=os.path.abspath(os.path.dirname(__file__))@bareasgi_jinja2.template('example1.html')asyncdefhttp_request_handler(scope,info,matches,content):return{'name':'rob'}app=Application()env=jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.join(here,'templates')),autoescape=jinja2.select_autoescape(['html','xml']),enable_async=True)bareasgi_jinja2.add_jinja2(app,env)app.http_router.add({'GET'},'/example1',http_request_handler)uvicorn.run(app,port=9010)