Django在模板中形成多个选择框大小 [英] Django form multiple select box size in template
本文介绍了Django在模板中形成多个选择框大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模板:
...
<form action="/reportform/" method="post">
<p><label>Aircraft system:</label>
<br>{{ Querry.system }}
...
它看起来像此
如何为此框设置大小选项?例如,10。
How can I set a Size option for this box? for example, 10.
推荐答案
使用attrs属性定义大小。
Use the attrs attribute to define the size.
class MyForm(forms.Form):
system = forms.ChoiceField(choices=SYSTEM_CHOICES,
widget=forms.SelectMultiple(attrs={'size':'40'}))
有时,覆盖窗体中的窗口小部件strong> init 方法。
Sometimes, it is useful to override the widget in the forms init method.
class MyForm(forms.Form):
<snip>
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['system'].widget = forms.SelectMultiple(attrs={'size':'40'}))
这篇关于Django在模板中形成多个选择框大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文