简体   繁体   中英

Difference between jinja2's autoescape extension and markupsafe library

Hi, this problem is specific to Python 2.7 Google App Engine platfrom.

Usually, you see something like this in your app.yaml :

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

I want to know what is markupsafe doing here.

Since jinja2 already has a "autoescape extension", why do we still need "markupsafe"?

Here Google App Engine Jinja2 and Markupsafe says: markupsafe makes jinja2 run faster. If this is the case, why do we need to include it explicitly while app engine can include it implicitly?

Any example on how to use this markupsafe on Google App Engine?

To answer your questions one at a time:

  1. Markupsafe is, as you guessed, a C library that speeds up the process of escaping HTML.

  2. Google does not include it implicitly when you create a Python environment because they decided not to do so - you need to opt-in to using Markupsafe (explicit is better than implicit perhaps?)

  3. Once you have Markupsafe installed Jinja will automatically use it (thus resulting in template speed-ups).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM