美文网首页
django_form_widget速查

django_form_widget速查

作者: 两点半的杂货铺 | 来源:发表于2018-02-25 22:22 被阅读37次

    一、widget自带的属性

    • attrs设置属性

    name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
    效果展示
    '<input title="Your name" type="text" name="name" value="A name" size="10" required />'

    user = fields.CharField(
     widget = widgets.Select(attrs={'class':'tss'})
    )
    

    二、widgets. 的方法

    • 文本类型(常用的)

    • widgets. TextInput 文本输入框

    input_type:'text'
    template_name:'django/forms/widgets/text.html'
    呈现为:< input type =“text” ...>;

    • widgets. PasswordInput密码本输入框

    input_type:'text'
    template_name:'django/forms/widgets/text.html'
    呈现为:< input type =“text” ...>;

    • widgets. HiddenInput密码本输入框

    input_type:'hidden'
    template_name:'django/forms/widgets/hidden.html'
    呈现为:&lt; input type =“hidden” ...&gt;

    • widgets. Textarea长文本

    template_name:'django/forms/widgets/textarea.html'
    呈现为:<textarea>...</textarea>

    • widgets. CheckboxInput Checkbox

    input_type:'checkbox'
    template_name:'django/forms/widgets/checkbox.html'
    呈现为:&lt; input type =“checkbox” ...&gt;
    一个可调用的对象,接收CheckboxInput 的值并如果复选框应该勾上返回True。

    • widgets. Select

    template_name:'django/forms/widgets/select.html'
    option_template_name:'django/forms/widgets/select_option.html'
    呈现为:&lt; select&gt;&lt; option ...&gt; ...&lt; / select&gt;

    • RadioSelect 单选

    template_name:'django/forms/widgets/radio.html'
    option_template_name:'django/forms/widgets/radio_option.html'

    • SelectMultiple 多选
    • template_name'django/forms/widgets/select.html'
    • option_template_name'django/forms/widgets/select_option.html'

    Select类似,但允许多个选择:&lt; select multiple =“multiple”&gt; ...&lt; / select&gt; t5 > T3>

    • CheckboxSelectMultiple 多选
    • FileInput 文件上传

    template_name:'django/forms/widgets/file.html'
    呈现为:&lt; input type =“file” ...&gt;

    相关文章

      网友评论

          本文标题:django_form_widget速查

          本文链接:https://www.haomeiwen.com/subject/twkdxftx.html