没有项目描述

jinja2-sanic的Python项目详细描述


build statuscoverage status

Sanic的Jinja2模板呈现程序。它支持:

  • 基于函数的Web处理程序
  • 基于类的视图
  • 方便使用的拆卸器

您可以在此处了解更多信息:

http://jinja2-sanic.readthedocs.io/en/latest/

安装

pip3 install jinja2-sanic

快速启动

fromsanicimportSanicfromsanic.viewsimportHTTPMethodViewfromsanic.exceptionsimportServerErrorapp=Sanic("sanic_jinja2_render")# Setup jinja2 environmenttemplate="<html><body><h1>{{Player}}</h1>{{Category}}</body></html>"jinja2_sanic.setup(app,loader=jinja2.DictLoader({"templates.jinja2":template}))# Usage in function based web handlers@app.route("/")@jinja2_sanic.template("templates.jinja2")asyncdeffunc(request):return{"Player":"CR7","Category":"Soccer",}# Usage in class-based viewsclassSimpleView(HTTPMethodView):@jinja2_sanic.template("templates.jinja2")asyncdefget(self,request):return{"Player":"CR7","Category":"Soccer",}# register class based view routesapp.add_route(SimpleView.as_view(),"/")# Start Serverif__name__=="__main__":app.run(host="0.0.0.0",port=8000)

开发

jinja2-sanic接受对github的贡献,以问题或请求的形式。

建造。

./uranium

运行单元测试。

./uranium test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
ByteArrayOutputStream的java解码属性   java S3 SDK在上载时更新单个对象,而不是创建新文件   java hibernate:无法从eclipse连接到DB   java如何在强制转换JComboBox之前检查其类型?   http从Java中的GETPOST请求方法捕获URI、资源名称,如开发人员工具中所示   java在Spring@Bean方法中返回接口的局限性   Java中的Web服务和客户端(使用Eclipse Apache Axis 2自底向上服务)某些代码会引发异常   java spring安全+rest不起作用   java将LinkedList添加到包含LinkedList的LinkedList并更改添加的LinkedList   java是否临时删除对象的属性?   java使用AnimatedGifEncoder类创建的gif图像的部分帧是不透明的   java如何高效地处理maven3时间戳快照?   java向集合对象添加另一项   java如何将动态参数传递给jquery函数   java使用libGdx桌面端口作为Android GLES20的仿真器