您的位置:首页 > Web前端 > CSS

django中form的CSS样式

2014-04-13 17:34 197 查看
On a real web page, you probably don't want every widget to look the same. You might want a larger input element for the comment, and you might want the 'name' widget to have some special CSS class. To do this, you use the attrs argument when creating
the widget:

Widget.attrs

For example:

class CommentForm(forms.Form):

name = forms.CharField(

widget=forms.TextInput(attrs={'class':'special'}))

url = forms.URLField()

comment = forms.CharField(

widget=forms.TextInput(attrs={'size':'40'}))


Django will then include the extra attributes in the rendered output:

>>> f = CommentForm(auto_id=False)

>>> f.as_table()

<tr><th>Name:</th><td><input type="text" name="name" class="special"/></td></tr>

<tr><th>Url:</th><td><input type="text" name="url"/></td></tr>

<tr><th>Comment:</th><td><input type="text" name="comment" size="40"/></td></tr>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: