jinja2

GitHub

提供Jinja2模板渲染的最佳实践,涵盖环境配置、过滤器使用、自动转义及安全性防护,防止XSS攻击。

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

Trigger Scenarios

需要渲染HTML或文本模板 涉及Jinja2模板安全配置

Install

npx skills add microsoft/debugpy --skill jinja2 -g -y
More Options

Non-standard path

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

Use without installing

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.

Version History

  • e5743d3 Current 2026-08-20 17:01

Same Skill Collection

.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

Metadata

Files
0
Version
e5743d3
Hash
4ae3f21a
Indexed
2026-08-20 17:01

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-30 23:47
浙ICP备14020137号-1 $mapa de visitantes$