(仅限Django 2& 2.0.1)
如果我使用{{form}}
它可以使用,但如果我使用{{form.field}}
它就会消失所有
<form method="POST" class="post-form" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" id="salva" class="btn btn-primary" />
</form>
forms.py
class PreventivoForm(forms.ModelForm):
class Meta:
model = Preventivo
fields = ['cliente','prestazione1', 'ripetizione1', 'prestazione2', 'ripetizione2', 'prestazione3', 'ripetizione3', 'prestazione4', 'ripetizione4', 'prestazione5', 'ripetizione5']
答案 0 :(得分:1)
当您使用{{form}}时,它会获得所有这些值:
<tr><th><label for="id_username">Username:</label></th><td><input type="text" name="username" autofocus maxlength="254" required id="id_username" /></td></tr>
<tr><th><label for="id_password">Password:</label></th><td><input type="password" name="password" required id="id_password" /></td></tr>
但如果您使用{{form.username}}和{{form.password}},那么:
<input type="text" name="username" autofocus maxlength="254" required id="id_username" />
<input type="password" name="password" required id="id_password" />
因此,您只会看到输入字段不是该输入字段的标签