我以为我正确地构建了我的脆皮表单,但它呈现为标准 django 表单而不是我自定义的脆皮表单:
表格.py:
class MyForm(forms.Form):
main_image = forms.ImageField()
second_image = forms.ImageField()
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.layout = Layout(
Div(SmallFileField('main_image', 'second_image')),
)
SmallFileField(基于引导程序):
{% load crispy_forms_field %}
<div id="div_{{ field.auto_id }}" class="control-group{% if form_show_errors%}{% if field.errors %} error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label %}
<label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 20px; height: 20px;"><img src="http://www.placehold.it/20x20/EFEFEF/AAAAAA" /></div>
<div class="fileupload-preview fileupload-exists thumbnail" style="width: 20px; height: 20px;"></div>
<span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="{{ field.html_name }}" id="id_{{ field.html_name }}" value="{{ field.value }}" /></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
{% include 'bootstrap/layout/help_text_and_errors.html' %}
</div>
表单.html
<form action='' enctype='multipart/form-data' method='post'>
{% crispy form %}
<input type="submit" value="{% trans "Submit" %}" class="btn"/>
</form>
PS。此表单是三步表单向导中的一步。我很欣赏你的想法!