jinja2

作成者: microsoft

Jinja2を使用したテンプレートレンダリングのベストプラクティス(環境、フィルター、自動エスケープ、セキュリティを含む)

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

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.

microsoftのその他のスキル

oss-growth
microsoft
OSS成長ハッカーのペルソナ
official
winapp-ui-automation
microsoft
コマンドラインからUI Automation(UIA)を使用して、実行中のWindowsアプリのUIを検査および操作します。AIエージェントや開発者がUIを検査する必要がある場合に使用します…
official
accessibility-aria-expert
microsoft
React/Fluent UIのWebビューにおけるアクセシビリティ問題を検出・修正します。スクリーンリーダー互換性のコードレビュー時、ARIAラベルの修正時、および…の確認時に使用します。
official
generate-canvas-app
microsoft
[DEPRECATED — 代わりに canvas-app を使用してください] 完全なPower Appsキャンバスアプリを生成します。
official
django
microsoft
Djangoウェブ開発のベストプラクティス(モデル、ビュー、テンプレート、テストを含む)
official
github-issue-creator
microsoft
生のメモ、エラーログ、音声入力、スクリーンショットを、簡潔なGitHub Flavored MarkdownのIssueレポートに変換します。ユーザーがバグ情報やエラーを貼り付けた際に使用します。
official
python-package-management
microsoft
依存関係管理にuvを使用し、タスク自動化にpoethepoetを使用します。
official
runtime-validation
microsoft
移行アプリケーションのランタイム検証 — テスト戦略(計画フェーズ)とテスト実行(検証フェーズ)をカバー:起動検証、…
official