Google App Engine Jinja2和Markupsafe [英] Google App Engine Jinja2 and Markupsafe

查看:120
本文介绍了Google App Engine Jinja2和Markupsafe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌表示,MarkupSafe使jina2运行速度更快此处



我已将它添加到我的Yaml文件中。

  libraries: 
- name:webapp2
版本:2.5.1
- 名称:jinja2
版本:latest
- name:markupsafe
版本:latest

Jina2表示会检查是否安装了markupsafe here



我的问题是,我怎么知道它正在工作?我通过我的jinja表格插入了一堆html,并没有被转义。总之,我阅读过文档,无法找到markupsafe所做的明确答案,以及为什么需要它。我拥有那个jinja2的唯一信息片段寻找它,并且让jinja更快。我不知道它是否真的有效。AFAIK markupsafe不会影响jinja2的语义,只会影响它的性能。

解析方案

因此,找出它是否奏效的唯一方法是定时。或者你可以停止担心。 :-) app.yaml语法看起来不错。



如果你想让jinja2转义你的变量,你必须在创建环境时打开autoescape,如下所示:

  env = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__ file__)),
autoescape = True)


Google says that MarkupSafe makes jina2 run faster here

I've added it to my Yaml file like this.

libraries:
- name: webapp2
  version: "2.5.1"
- name: jinja2
  version: latest
- name: markupsafe
  version: latest

Jina2 says it checks to see if markupsafe is installed here

My question is, how do I really know it is working? I inserted a bunch of html via my jinja form and it didn't get escaped. In short, I've read the docs and can't find a clear answer to what markupsafe does, and why I need it. The only snippet of information I have that jinja2 looks for it and makes jinja faster. I have no idea if its really working.

解决方案

AFAIK markupsafe doesn't affect the jinja2 semantics, only its performance. So the only way to find out if it worked is to time it. Or you could stop worrying. :-) That app.yaml syntax looks fine.

If you want jinja2 to escape your variables, you must turn on autoescape when creating the Environment, like this:

env = jinja2.Environment(
  loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
  autoescape=True)

这篇关于Google App Engine Jinja2和Markupsafe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆