Google App Engine Jinja2 and Markupsafe

2019-05-09 16:08发布

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.

1条回答
Viruses.
2楼-- · 2019-05-09 16:58

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)
查看更多
登录 后发表回答