我目前正在学习django crispy forms,并将它们整合到我的项目中。但我决定使用django-user-accounts来处理用户配置文件。我遇到的问题是试图对所提供的表单进行样式设置。我引用了pinax-theme-bootstrap来创建模板,并为大多数所需的模板设计了以下内容:
<form method="POST" action="">
<legend>Change password</legend>
<fieldset>
{% csrf_token %}
{{ form }}
<button type="submit" class="btn btn-primary">Save</button>
</fieldset>
</form>
将css类添加到所有<label>
和字段的最佳方法是什么?将类添加到单个<input>
标记的最佳方式是什么?是否可以在像django-user-accounts这样的第三方应用程序上使用易碎的表单?
发布于 2014-10-02 20:26:49
我找到的解决方案是显式地遍历表单中的字段,同时分别列出字段和标签,并使用django-widget-tweaks向字段添加css类。
{% load widget_tweaks %}
{% for field in form %}
<div class="fieldWrapper">
{% if not field.is_hidden %}
<label for="{{field.id_for_label}}" class="col-lg-2">{{ field.label }}</label>
{% endif %}
{{ field|add_class:"col-lg-8"}}
{% if field.errors %}
<p class="error">{{ field.errors }}</p>
{% endif %}
</div>
{% endfor %}
我找不到任何使用django-crispy-forms的解决方案。
https://stackoverflow.com/questions/26147927
复制相似问题