12

I have started using Jinja2 as my templating engine on Google App Engine (in Python).

My question is this: Will bytecode caching work in production? It is working very well on the development server, but I read somewhere that bytecode caching depends on the marshal module, which is not supported in App Engine. This answer to a different question provides a possible solution by changing marshal to use pickle methods. Has anyone tried this?

In general, is there anything else that I should take into consideration when using Jinja2 with App Engine?

Any help would be greatly appreciated!

Thanks.

4

3 回答 3

12

Rodrigo Moraes 在 GAE 下为 Jinja2 创建了一些特殊的加载器,请参见此处。它不是字节码缓存,而是将所有模板预编译为 Python,因此您可以避免 Jinja2 解析开销。

请注意(来自此 GAE 页面):

已编译的应用程序代码被缓存以快速响应 Web 请求

于 2010-03-03T06:25:49.993 回答
9

Jinja2 现在包含在 GAE 中。显然您需要将您的应用程序迁移到 Python 2.7。

在 app.yaml 添加

libraries:
- name: jinja2
  version: "2.6"

以下是此信息的来源:http: //blog.notdot.net/2011/11/Migrating-to-Python-2-7-part-2-Webapp-and-templates

于 2012-01-25T13:11:27.937 回答
1

根据Python 2.7 文档中的新增功能,您还可以使用 Python 2.7 上传 .pyc 文件。

可以上传 .pyc 文件,但不能与 .py 文件结合使用。但是,您可以上传包含 .py 或 .pyc 文件(或组合)的 .zip 文件。

于 2012-06-21T05:54:03.893 回答