Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django迭代ClearableFileInput小部件字段_Python_Html_Django_Django Templates - Fatal编程技术网

Python Django迭代ClearableFileInput小部件字段

Python Django迭代ClearableFileInput小部件字段,python,html,django,django-templates,Python,Html,Django,Django Templates,当前有一个具有model.FileField()属性的模型,在django模板中呈现时,我只需迭代字段,例如 {% for field in form.visible_fields %} <div class="form-group"> {{field.errors}} <label for="{{field.auto_id}}">{{field.label}}</label> {{field}} {% endfor %}

当前有一个具有
model.FileField()
属性的模型,在django模板中呈现时,我只需迭代字段,例如

{% for field in form.visible_fields %}
    <div class="form-group">
    {{field.errors}}
    <label for="{{field.auto_id}}">{{field.label}}</label>
    {{field}}
 {% endfor %}
{%for form.visible\u fields%}
{{field.errors}}
{{field.label}
{{field}}
{%endfor%}

但是,当模板呈现
ClearableFileInput
小部件时,我想在
href
和用于清除小部件的复选框之间添加一些空间。关于如何访问字段的特定“部分”有什么想法吗?

您必须覆盖默认的
ClearableFileInput
,并根据自己的喜好设置这些呈现属性

class MyClearableInput(ClearableFileInput):
    template_with_initial = '%(initial_text)s: %(initial)s %(clear_template)s<br />%(input_text)s: %(input)s'
    template_with_clear = '%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label>'
    url_markup_template = '<a href="{0}">{1}</a>'
类MyClearableInput(ClearableFileInput):
带首字母='%(首字母文本)s:%(首字母)s%(清除模板)s
%(输入文本)s:%(输入)s' 模板_与_clear='%(clear)s%(clear_复选框_标签)s' url\标记\模板=“”
我已经设置了初始属性,但您必须更改它们以反映所需的输出。这是不言自明的。然后在表单中,使用
Meta/widgets
属性重写小部件以使用此类