我在将表单控件的HTML添加到我的Django表单时遇到了问题。我知道(从其他功能)我将Bootstrap正确地集成到项目中。当我尝试将表单控件集成到页面中时,没有显示任何字段。
表单有两个字段:1)文件字段,2)布尔字段。下面是我的HTML(我不会在/关闭标签后包含提交按钮。
<form id='name' action = "" method="POST" enctype="multipart/form-data" class="form-horizontal">
{% csrf_token %}
<div class="form-group">
<div class="col-md-4">
<!-- {{ form }} --> #Note that when this is not commented out and when the lines below are commented out, the form works correctly, but obviously with no form control.
{% for field in form.visible_fields %}
{% if field.auto_id == "file" %}
<div class="form-group{% if field.errors%} has-error{% endif %}">
<div class="col-sm-5 col-md-4 col-xs-8 col-lg-4 col-xl-4">
<label for="file">File input</label>
<input type="file" class="form-control-file" id="file" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">Test</small>
<div class="input-group">
<div class="input-group-addon">$</div>
{{field}}
</div>
{{ field.errors }}
</div>
</div>
{% else %}
{% endif %}
{% endfor %}
非常感谢任何帮助!