jinja2

GitHub

提供 Jinja2 模板渲染的最佳实践,涵盖环境配置、过滤器使用、模板继承及安全防护(如自动转义和沙箱环境),适用于 HTML、邮件及代码生成等场景。

.claude/skills/jinja2/SKILL.md microsoft/debugpy

触发场景

使用 Jinja2 渲染 HTML 页面或邮件 需要生成配置文件或代码 处理模板安全与 XSS 防护

安装

npx skills add microsoft/debugpy --skill jinja2 -g -y
更多选项

非标准路径

npx skills add https://github.com/microsoft/debugpy/tree/main/.claude/skills/jinja2 -g -y

不安装直接使用

npx skills use microsoft/debugpy@jinja2

指定 Agent (Claude Code)

npx skills add microsoft/debugpy --skill jinja2 -a claude-code -g -y

安装 repo 全部 skill

npx skills add microsoft/debugpy --all -g -y

预览 repo 内 skill

npx skills add microsoft/debugpy --list

SKILL.md

Frontmatter
{
    "name": "jinja2",
    "description": "Best practices for template rendering with Jinja2 including environments, filters, autoescaping, and security."
}

Skill: Jinja2

Best practices for template rendering with Jinja2 including environments, filters, autoescaping, and security.

When to Use

Apply this skill when rendering templates with Jinja2 — HTML pages, emails, configuration files, and code generation.

Environment

  • Create a jinja2.Environment(loader=..., autoescape=...) once and reuse it.
  • Use FileSystemLoader for file-based templates, PackageLoader for installed packages.
  • Enable autoescape=True for HTML templates to prevent XSS.

Templates

  • Use {{ variable }} for output, {% if/for/block %} for control flow.
  • Use template inheritance ({% extends 'base.html' %}) for layout reuse.
  • Define custom filters for reusable transformations.

Security

  • Always enable autoescape=True when rendering HTML.
  • Use SandboxedEnvironment for untrusted templates.
  • Never render user input as template code — only as template data.
  • Use |e filter explicitly when autoescape is off.

Pitfalls

  • Don't use Template(string) directly — it bypasses the environment's loader and settings.
  • Watch for undefined variable errors — use undefined=StrictUndefined during development.
  • Avoid complex logic in templates — keep them focused on presentation.

版本历史

  • e5743d3 当前 2026-08-20 17:01

同 Skill 集合

.claude/skills/click/SKILL.md
.claude/skills/django/SKILL.md
.claude/skills/flask/SKILL.md
.claude/skills/numpy/SKILL.md
.claude/skills/pytest/SKILL.md
.claude/skills/requests/SKILL.md

元信息

文件数
0
版本
e5743d3
Hash
4ae3f21a
收录时间
2026-08-20 17:01

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-28 23:44
浙ICP备14020137号-1 $访客地图$