mcpbeat

Jinja2

microsoft/jinja2

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

357 tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
2448
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/microsoft/debugpy --skill jinja2

The instruction itself

6 sections, as written by the author

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.

How to use it

Copy the folder

Take microsoft/jinja2 from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.