跳转到主要内容

预编译Jinja2模板为Python字节码

项目描述

预编译Jinja2模板为Python字节码。

用法

Jinja2预编译器附带一个名为jinja2precompiler的实用脚本。请在命令行提示符下输入jinja2precompiler --help以了解更多关于此工具的信息。

编译Jinja2模板

然后运行jinja2precompiler命令

$ jinja2precompiler templates
Compiling into folder "templates"
...
Compiled "templates/template.html" as tmpl_5f0fcb0ed56efa600c50d9f2870192327823c063.py
...
Finished compiling templates

使用--pyc选项编译为Python字节码

$ jinja2precompiler --pyc templates
Compiling into folder "templates"
...
Compiled "templates/template.html" as tmpl_5f0fcb0ed56efa600c50d9f2870192327823c063.pyc
...
Finished compiling templates

获取编译后的模块名称

使用--modulename选项将返回模块文件名

$ jinja2precompiler --modulename templates/template.html
tmpl_41d3b4a4b71afe0c223778e57c23244caee1baec.py

$ jinja2precompiler --modulename --pyc templates/template.html
tmpl_41d3b4a4b71afe0c223778e57c23244caee1baec.pyc

您可以使用--base选项添加目录路径

$ jinja2precompiler --modulename --base=templates templates/template.html
templates/tmpl_5f0fcb0ed56efa600c50d9f2870192327823c063.py

如果您指定了多个参数,将返回指定的模块文件名

$ jinja2precompiler --modulename a.html b.html c.html
tmpl_25e7e8960b03ecb19189f36b8ef611389397c95c.py tmpl_83d0d31e29a7746a19536d616218a384f62d4694.py tmpl_45ecd51cee2d33904a8cd1af7c441dd3fc320870.py

使用Make

示例Makefile文件

templates_compiled.zip: $(wildcard templates/*.html)
      jinja2precompiler -c templates
      zip -FS -j templates_compiled.zip templates/*.pyc

仅编译更新的文件并将其存储到zip文件中。

安装

使用pip从PyPI安装

pip install jinja2precompiler

使用easy_install从PyPI安装

easy_install jinja2precompiler

从源代码安装

python setup.py install

依赖项

  1. Jinja2

变更

0.2:支持遍历符号链接目录

许可

Jinja2预编译器根据BSD 3-Clause许可证的条款进行许可。

版权所有 2012 ENDOH takanao.

项目的源代码可在GitHub上获取。请将错误报告和增强请求提交至问题跟踪器

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

jinja2-precompiler-0.2.tar.gz (154.7 kB 查看哈希值)

上传时间 源代码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面