1、前端循环:后端传到前端的form是可以循环的,以此获得想要展示的元素
<form method="post" class="form-horizontal" novalidate> {% csrf_token %} {% for field in form %} <div class="col-sm-6"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">{{ field.label }}</label> <div class="col-sm-10"> {{ field }} {{ field.errors.0 }} </div> </div> </div> {% endfor %} <div class="col-sm-offset-11 col-sm-1"> <input type="submit" class="btn btn-primary" value="提交"> </div> </form>
{{ field.label }}:models.py中的verbose_name {{ field }}:input框 {{ field.errors.0 }}:字段的错误信息