mcpField
J
jinja2

jinja2

github.com/microsoftDevelopment2.5k50 installsUpdated 1d ago
Repository

About jinja2

A practical Jinja2 skill for developers rendering HTML, email, configuration, and code-generation templates. It covers environment reuse, template structure, and safeguards against unsafe rendering.

Key features

  1. 01Reusable environment configuration
  2. 02File and package template loaders
  3. 03Template inheritance and custom filters
  4. 04Autoescaping and sandboxing guidance
  5. 05Strict undefined checks during development

Use cases

  1. 01Render HTML while reducing XSS risk
  2. 02Reuse layouts across templates
  3. 03Handle untrusted template definitions
  4. 04Generate configuration files or code

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/microsoft/debugpy --skill jinja2

After installing, type/jinja2in Claude Code to confirm it loaded.

Details

From the project README

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.

Comments

Markdown supported