... の基本を示した最小限のテンプレートです。各要素については、この文書の後半で説明します。 {% extends "base_generic.html" %} {% block title %}{{ section.title }}{% endblock %} {% block content %} < h1 > {{ section.title }} </ h1 > {% for story in story_lis ... } " > {{ story.headline | upper }} </ a > </ h2 > < p > {{ story.tease | truncatewords :"100" }} </ p > {% endfor %} {% endblock %} 設計思想 なぜ、(ZopeのTALのような) XMLベースのテンプレートではなく、テキストベースのテンプレートを使うのか?それは、Djan ... ィルタは文字列を返すので、フィルタを使った数学的な比較は通常は期待通りにならないことに注意してください。 length は例外です。 block と extends テンプレートの "定型文" を削減する強力な方法である template inheritance (下記参照)を設定します。 繰り返します ... ... の基本を示した最小限のテンプレートです。各要素については、この文書の後半で説明します。 {% extends "base_generic.html" %} {% block title %}{{ section.title }}{% endblock %} {% block content %} < h1 > {{ section.title }} </ h1 > {% for story in story_lis ... } " > {{ story.headline | upper }} </ a > </ h2 > < p > {{ story.tease | truncatewords :"100" }} </ p > {% endfor %} {% endblock %} 設計思想 なぜ、(ZopeのTALのような) XMLベースのテンプレートではなく、テキストベースのテンプレートを使うのか?それは、Djan ... ィルタは文字列を返すので、フィルタを使った数学的な比較は通常は期待通りにならないことに注意してください。 length は例外です。 block と extends テンプレートの "定型文" を削減する強力な方法である template inheritance (下記参照)を設定します。 繰り返します ... ... w rules in Django template code. {% extends %} should be the first non-comment line. Do this: {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Or this: {# This is a c ... omment #} {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Don't do this: {% load ... i18n %} {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Put exactly one space b ... ... w rules in Django template code. {% extends %} should be the first non-comment line. Do this: {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Or this: {# This is a c ... omment #} {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Don't do this: {% load ... i18n %} {% extends "base.html" %} {% block content %} < h1 class = "font-semibold text-xl" > {{ pages.title }} </ h1 > {% endblock content %} Put exactly one space b ... ... _ready ブロックを拡張し、イベントリスナーのコードを追加します: {% extends 'admin/change_form.html' %} {% load static %} {% block admin_change_form_document_ready %} {{ block .super }} < script src = " {% static 'app/formset_handlers.js' %} " ></ scrip ... t > {% endblock %} app/static/app/formset_handlers.js ¶ document . addEventListener ( 'formset:added' , ( event ) => { if ( event . detail ... ge_form_document_ready ブロックには、変更フォーム内でのさまざまな操作を処理するための JavaScript コードが含まれており、 {{ block.super }} は、それらもレンダリングする必要があるために追加されています。 バージョン4.1より前のDjangoをサポートする ¶ もしイ ... ... te.html テンプレートにカスタムロゴを追加できます: templates/admin/base_site.html ¶ {% extends "admin/base_site.html" %} {% block branding %} < img src = "link/to/logo.png" alt = "logo" > {{ block .super }} {% endblock %} 備考: この例では、 templates/a ... れはオーバーライドされるテンプレートと同じです。 このテンプレートは branding ブロックだけを置き換え、カスタムロゴを追加し、 block.super を使って以前のコンテンツを保持します。 残りのテンプレートは admin/base_site.html からそのまま継承されます。 このテク ... するときに、すでにロードされているオーバーライドテンプレート ( templates/admin/base_site.html ) を考慮しないので動作します。 block.super と組み合わせることで、小さなカスタマイズを行うための強力なテクニックとなります。 目次 テンプレートをオーバーライドす ... ... te.html テンプレートにカスタムロゴを追加できます: templates/admin/base_site.html ¶ {% extends "admin/base_site.html" %} {% block branding %} < img src = "link/to/logo.png" alt = "logo" > {{ block .super }} {% endblock %} 備考: この例では、 templates/a ... れはオーバーライドされるテンプレートと同じです。 このテンプレートは branding ブロックだけを置き換え、カスタムロゴを追加し、 block.super を使って以前のコンテンツを保持します。 残りのテンプレートは admin/base_site.html からそのまま継承されます。 このテク ... するときに、すでにロードされているオーバーライドテンプレート ( templates/admin/base_site.html ) を考慮しないので動作します。 block.super と組み合わせることで、小さなカスタマイズを行うための強力なテクニックとなります。 目次 テンプレートをオーバーライドす ... ... %M %p" as the_time %} < p > The time is {{ the_time }} . </ p > シンプル・ブロック・タグ ¶ django.template.Library. simple_block_tag () ¶ When a section of rendered template needs to be passed into a custom tag, Django provides the simple_block_tag he ... ます: from django import template from myapp.charts import render_chart register = template . Library () @register . simple_block_tag def chart ( content ): return render_chart ( source = content ) content 引数には、 {% chart %} と {% endchart %} タグの ... me} (たとえば endchart )で閉じます。この閉じタグの名前は、 end_name パラメータでカスタマイズできます: @register . simple_block_tag ( end_name = "endofchart" ) def chart ( content ): return render_chart ( source = content ) この場合、テンプレートの定 ... ... %M %p" as the_time %} < p > The time is {{ the_time }} . </ p > シンプル・ブロック・タグ ¶ django.template.Library. simple_block_tag () ¶ When a section of rendered template needs to be passed into a custom tag, Django provides the simple_block_tag he ... ます: from django import template from myapp.charts import render_chart register = template . Library () @register . simple_block_tag def chart ( content ): return render_chart ( source = content ) content 引数には、 {% chart %} と {% endchart %} タグの ... me} (たとえば endchart )で閉じます。この閉じタグの名前は、 end_name パラメータでカスタマイズできます: @register . simple_block_tag ( end_name = "endofchart" ) def chart ( content ): return render_chart ( source = content ) この場合、テンプレートの定 ... ... ます。 Documentation quality checks ¶ Several checks help maintain Django's documentation quality, including spelling , code block formatting , and documentation style . These checks are run automatically in CI and must pass before documentation changes ... と確信できる場合のみ、その単語を docs/spelling_wordlist に追加してください(リストはアルファベット順にしてください)。 Code block format check ¶ All Python code blocks should be formatted using the blacken-docs auto-formatter. This is automatically run ... ke black ...\> make.bat black The formatter will report any issues by printing them to the terminal and will reformat code blocks where possible. Documentation lint check ¶ Django's documentation is checked for reStructuredText style and formal issues ... 2026年10月08日