如何生成< span>而不是< li>标签 [英] how to produce <span> instead of <li> tag
问题描述
forms.py
class ZergitForm(forms.Form):
zerg_selection = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),required=False)
views.py
def feeds(request):
if request.method == 'POST':
zergform = ZergitForm(request.POST)
""""""""
some other logic comes here
""""""""
selection = ZergitForm(zerg_id)
return render(request, 'feed_list.html',{'zerg_selection':zerg_selection})
feed_list.html
feed_list.html
{% for feed in selection.zerg_selection %}
<span class="checkbox_select">{{ feed }}</span>
{% endfor %}
问题是将渲染列为复选框列表一个< li>
标签。但是我需要的是输入字段与< span>
标签。如何在我的应用程序中实现它。
Problem is it is rendering as a list of check boxes in a <li>
tag.But what i required is the input field with check box inside the <span>
tag.How to implement it in my application.
推荐答案
没有干净的解决方案,您可以使用覆盖的render方法定义自己的CheckboxSelectMultiple小部件很多开销):
There is no clean solution for that, either you define your own CheckboxSelectMultiple widget with overridden render method (which imho, is way to much overhead):
https://github.com/django/django/blob/1.5.2/django/forms/widgets.py#L754
或您使用小黑客(在这种情况下,您将替换< li>
和< / li>
等):
or you use small hack (in that case you replace <li>
and </li>
etc):
Django设置类< ul>而不是< input>使用CheckboxSelectMultiple widget
或自定义模板输出:
https://stackoverflow.com/a/15441506/1566605
这篇关于如何生成< span>而不是< li>标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!