Jinja2 是为 Python 提供的一个功能齐全的模板引擎。Jinja2提供了对 Unicode 的完整支援,以及一个可选集成的沙盒运行环境。它使用BSD协议。
主要特性:
- 沙盒执行模式
- 针对跨站脚本攻击的自动HTML转义系统
- 模板继承
- 即时编译(just-in-time compilation)
- 可选的静态编译 (ahead-of-time compilation)
- 内置调试系统
- 语言风格可配置
- 设计助手
简单的例子
<!DOCTYPE html>
<html>⑨
<head>
<title>{{ variable|escape }}</title>
</head>
<body>
{%- for item in item_list %}
{{ item }}{% if not loop.last %},{% endif %}
{%- endfor %}
</body>
</html>
他们在使用Jinja2:
引用
外部链接
Wikiwand in your browser!
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.