jinja2

Other Community

Skill notes

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.

Fluxly profile Runtime and permissions are inferred by Fluxly static checks, not author declarations or runtime test results.
Domain
Other
Author-declared agents
No explicit declaration found; this is not inferred or tested compatibility
Static check
94 / 100 · heuristic scan, not runtime safety proof
Runtime evidence
Not run; no isolated runtime test evidence is currently recorded
Author / version / license
@microsoft · NOASSERTION
Token usage
Lean
Setup complexity
Plug-and-play
External API key
Not required
Operating systems
Unspecified (assume cross-platform)
Runtime requirements
No explicit requirements detected
Detected file/system behavior
  • Read-only
  • Write / modify
Network behavior
Local-only
Install commands
None (reference only)

Heads up: Tool permissions are not declared; actual access depends on the runtime.

Author source file SKILL.md

# 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.

Discussion

Powered by GitHub Discussions. Sign in with GitHub to comment, react, or subscribe.