【发布时间】:2015-11-23 08:05:29
【问题描述】:
所以我使用 django 用户模型(来自 django.contrib.auth.models 导入用户)并使用 ModelForm(来自 django.forms 导入 ModelForm)创建了一个模型表单。当我在模板上显示它时,它作为用户名显示在选择框上。我想显示它是名字和姓氏。
这是我在 HTML 中用于表单的代码
<form class="form-horizontal" method="post" role="form">
{% csrf_token %}
<fieldset>
<legend>{{ title }}</legend>
{% for field in form %} {% if field.errors %}
<div class="form-group">
<label class="control-label col-sm-2">{{ field.label }}</label>
<div class="controls col-sm-10">
{{ field }}
<p class="formError">
{% for error in field.errors %}{{ error }}{% endfor %}
</p>
</div>
</div>
{% else %}
<div class="form-group">
<label class="control-label col-sm-2">{{ field.label }}</label>
<div class="controls col-sm-10">
{{ field }} {% if field.help_text %}
<p class="help-inline"><small>{{ field.help_text }}</small></p>
{% endif %}
</div>
</div>
{% endif %} {% endfor %}
</fieldset>
<div class="form-actions" style="margin-left: 150px; margin-top: 30px;">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
【问题讨论】:
标签: django django-models django-forms django-templates django-views