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:
Django will then include the extra attributes in the rendered output:
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>
相关文章推荐
- div + css + Js 实现 select 多选列表 完整实例
- css
- 自制“低奢内”CSS3注册表单,包含JS验证哦。请别嫌弃,好吗?。
- CSS的知识回顾(4.8-4.13)
- border-radius 圆角边框(CSS3.0)
- html和css
- CSS 颜色名
- 建造样式与抽象工厂样式的区别
- CSS中的各种属性记录(一)
- [转]关于浏览器css选择器性能优化
- css中定位中的fixed是什么意思
- 浏览器对脚本和样式表的处理顺序
- css之float和clear
- css(hr元素)水平线的定位
- 对a:link,a:visited,a:hover,a:active理解
- 妙味云课堂之css:滑动门、圆角、css精灵
- css sprite图片优化技术
- div样式text-align在子元素缩进不规范的情况下,chrome出现的问题(貌似结果是inline-block导致的)
- 超赞的CSS3进度条 可以随进度显示不同颜色
- 用CSS3制作很特别的波浪形菜单