posts - 431,  comments - 344,  trackbacks - 0

          If your site uses the same rendering logic for forms in multiple places, you can reduce duplication by saving the form's loop in a standalone template and using the include tag to reuse it in other templates:

          <form action="/contact/" method="POST">
          {% include "form_snippet.html" %}
          <p><input type="submit" value="Send message" /></p>
          </form>
          # In form_snippet.html:
          {% for field in form %}
          <div class="fieldWrapper">
          {{ field.errors }}
          {{ field.label_tag }}: {{ field }}
          </div>
          {% endfor %}
          

          If the form object passed to a template has a different name within the context, you can alias it using the with tag:

          <form action="/comments/add/" method="POST">
          {% with comment_form as form %}
          {% include "form_snippet.html" %}
          {% endwith %}
          <p><input type="submit" value="Submit comment" /></p>
          </form>
          

          If you find yourself doing this often, you might consider creating a custom inclusion tag.

          posted on 2009-04-03 11:58 周銳 閱讀(125) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Python
          主站蜘蛛池模板: 分宜县| 博罗县| 邓州市| 金沙县| 紫金县| 榆社县| 贵定县| 霍林郭勒市| 肥城市| 肥乡县| 阿拉善右旗| 贵德县| 三都| 西吉县| 白银市| 永清县| 台安县| 乡宁县| 阿拉善盟| 乌拉特中旗| 赣州市| 土默特左旗| 万宁市| 怀宁县| 南澳县| 汝州市| 永善县| 韶山市| 克山县| 时尚| 河源市| 繁峙县| 洪湖市| 宿迁市| 鲁甸县| 怀仁县| 阿城市| 淅川县| 沙坪坝区| 晋宁县| 民和|