引导表单控件-Django表单HTML
我在向Django表单添加表单控件的HTML时遇到了问题。我知道(从其他特性)我已经将引导正确地集成到项目中。当我尝试将表单控件集成到页面中时,没有显示任何字段 表单有两个字段:1)文件字段和2)布尔字段。下面是我的HTML(我不包括提交按钮后/关闭标签)引导表单控件-Django表单HTML,html,django,forms,twitter-bootstrap,twitter-bootstrap-3,Html,Django,Forms,Twitter Bootstrap,Twitter Bootstrap 3,我在向Django表单添加表单控件的HTML时遇到了问题。我知道(从其他特性)我已经将引导正确地集成到项目中。当我尝试将表单控件集成到页面中时,没有显示任何字段 表单有两个字段:1)文件字段和2)布尔字段。下面是我的HTML(我不包括提交按钮后/关闭标签) <form id='name' action = "" method="POST" enctype="multipart/form-data" class="form-horizontal"> {% csrf_token %}
<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 %}
{%csrf_令牌%}
#请注意,如果没有注释掉这一点,并且注释掉下面的行,则表单可以正常工作,但显然没有表单控件。
{%form.visible_fields%}
{%if field.auto_id==“文件”%}
文件输入
试验
$
{{field}}
{{field.errors}}
{%else%}
{%endif%}
{%endfor%}
非常感谢您的帮助!现在有什么问题?没有显示任何字段?正确,没有显示任何字段。更新了说明。是的,因为您使用了错误的名称,请发布您的模型表单或要渲染的表单。请使用field.auto\u id将其更改为field.label==“文件”调试:在
else
子句中输出字段标签,您将看到它是否进入if
块。