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) 評論(0)  編輯  收藏 所屬分類: Python
          主站蜘蛛池模板: 余江县| 蒲城县| 平原县| 卫辉市| 宁夏| 马公市| 谷城县| 浪卡子县| 邢台县| 家居| 长治市| 浦东新区| 铁力市| 喀喇沁旗| 七台河市| 东阳市| 调兵山市| 南昌县| 温州市| 梨树县| 吐鲁番市| 东乡| 古浪县| 德庆县| 兰西县| 灵寿县| 普宁市| 阿尔山市| 乐至县| 阜新市| 聂荣县| 桦南县| 武隆县| 曲水县| 巴彦淖尔市| 新兴县| 尼玛县| 清水县| 卓尼县| 大兴区| 津南区|