我正在使用django表单,我想在我的HTML中使用Twitter Bootstrap的css.所以我的模板看起来像这样:
{% for field in form %}
<div class="form-group">
{{ field.label_tag }}<!--Same thing as : <label for="{{field.id_for_label}}"></label> -->
<input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="Email">
</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚是否获得了类型值.{{field.type}}.
有没有办法在django模板中获取输入字段的类型?
提前致谢
更新:
我问这个问题的原因是因为我希望能够将bootstrap类应用于input元素.但是在Bootstrap3中,要使用默认的css作为输入类型,你必须将form-control类添加到input元素,如下所示:<input type="text" class="form-control" id="{{field.auto_id}}" placeholder="">.
如果我使用django的字段,{{field}}那么我无法添加表单控件类.我希望这能澄清一些事情.
我也看到了这个应用程序https://github.com/dyve/django-bootstrap3看起来像我想做的事情.令我惊讶的是,django不允许访问表单类型以允许更大的灵活性.