[英]Django python change multipleChoiceField html output
I have multipleChicesField: 我有多个ChicesField:
OPTIONS = (
("AUT", "Austria"),
("DEU", "Germany"),
("NLD", "Neitherlands"),
)
countries = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(attrs={"name": "select_0","class": "fff"}),
choices=OPTIONS)
Right now it produces following html: 现在,它产生以下html:
<ul id="id_countries">
<li><label for="id_countries_0"><input class="fff" id="id_countries_0" name="countries" type="checkbox" value="AUT"> Austria</label></li>
<li><label for="id_countries_1"><input class="fff" id="id_countries_1" name="countries" type="checkbox" value="DEU"> Germany</label></li>
<li><label for="id_countries_2"><input class="fff" id="id_countries_2" name="countries" type="checkbox" value="NLD"> Neitherlands</label></li>
</ul>
How do I change my code to produce html structure something like: 如何更改代码以生成类似以下内容的html结构:
<div class="someClass">
<input class="fff" id="id_countries_0" name="countries" type="checkbox" value="AUT">
<label for="id_countries_0">Austria</label>
</div>
<div class="someClass">
<input class="fff" id="id_countries_1" name="countries" type="checkbox" value="DE">
<label for="id_countries_0">Germany</label>
</div>
You can render the form manually, and then use whatever markup you like 您可以手动呈现表单,然后使用所需的任何标记
https://docs.djangoproject.com/en/1.10/topics/forms/#rendering-fields-manually https://docs.djangoproject.com/en/1.10/topics/forms/#rendering-fields-manually
See this example for looping through each form field: 请参见以下示例,以遍历每个表单字段:
https://docs.djangoproject.com/en/1.10/topics/forms/#looping-over-the-form-s-fields https://docs.djangoproject.com/en/1.10/topics/forms/#looping-over-the-form-s-fields
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.