<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    Widgets

    A widget is Django’s representation of a HTML input element. The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget.

    Django provides a representation of all the basic HTML widgets, plus some commonly used groups of widgets:

    class TextInput
    Text input: <input type='text' ...>
    class PasswordInput

    Password input: <input type='password' ...>

    Takes one optional argument:

    render_value
    Determines whether the widget will have a value filled in when the form is re-displayed after a validation error (default is True).
    class HiddenInput
    Hidden input: <input type='hidden' ...>
    class MultipleHiddenInput
    Multiple <input type='hidden' ...> widgets.
    class FileInput
    File upload input: <input type='file' ...>
    class DateInput
    New in Django 1.1: Please, see the release notes

    Date input as a simple text box: <input type='text' ...>

    Takes one optional argument:

    format
    The format in which this field’s initial value will be displayed.

    If no format argument is provided, the default format is '%Y-%m-%d'.

    class DateTimeInput
    New in Django 1.0: Please, see the release notes

    Date/time input as a simple text box: <input type='text' ...>

    Takes one optional argument:

    format
    The format in which this field’s initial value will be displayed.

    If no format argument is provided, the default format is '%Y-%m-%d %H:%M:%S'.

    class TimeInput

    Time input as a simple text box: <input type='text' ...>

    Takes one optional argument:

    format
    The format in which this field’s initial value will be displayed.

    If no format argument is provided, the default format is '%H:%M:%S'.

    Changed in Django 1.1: The format argument was not supported in Django 1.0.
    class Textarea
    Text area: <textarea>...</textarea>
    class CheckboxInput

    Checkbox: <input type='checkbox' ...>

    Takes one optional argument:

    check_test
    A callable that takes the value of the CheckBoxInput and returns True if the checkbox should be checked for that value.
    class Select

    Select widget: <select><option ...>...</select>

    Requires that your field provides choices.

    class NullBooleanSelect
    Select widget with options ‘Unknown’, ‘Yes’ and ‘No’
    class SelectMultiple

    Select widget allowing multiple selection: <select multiple='multiple'>...</select>

    Requires that your field provides choices.

    class RadioSelect

    A list of radio buttons:

    <ul>
    <li><input type='radio' ...></li>
    ...
    </ul>

    Requires that your field provides choices.

    class CheckboxSelectMultiple

    A list of checkboxes:

    <ul>
    <li><input type='checkbox' ...></li>
    ...
    </ul>
    class MultiWidget
    Wrapper around multiple other widgets
    class SplitDateTimeWidget

    Wrapper around two widgets: DateInput for the date, and TimeInput for the time.

    Takes two optional arguments, date_format and time_format, which work just like the format argument for DateInput and TimeInput.

    Changed in Django 1.1: The date_format and time_format arguments were not supported in Django 1.0.
    class SelectDateWidget

    Wrapper around three select widgets: one each for month, day, and year. Note that this widget lives in a separate file from the standard widgets.

    from django.forms.extras.widgets import SelectDateWidget

    date = forms.DateField(widget=SelectDateWidget())

    Specifying widgets

    Form.widget

    Whenever you specify a field on a form, Django will use a default widget that is appropriate to the type of data that is to be displayed. To find which widget is used on which field, see the documentation for the built-in Field classes.

    However, if you want to use a different widget for a field, you can - just use the 'widget' argument on the field definition. For example:

    from django import forms

    class CommentForm(forms.Form):
    name = forms.CharField()
    url = forms.URLField()
    comment = forms.CharField(widget=forms.Textarea)

    This would specify a form with a comment that uses a larger Textarea widget, rather than the default TextInput widget.

    Customizing widget instances

    When Django renders a widget as HTML, it only renders the bare minimum HTML - Django doesn't add a class definition, or any other widget-specific attributes. This means that all 'TextInput' widgets will appear the same on your web page.

    If you want to make one widget look different to another, you need to specify additional attributes for each widget. When you specify a widget, you can provide a list of attributes that will be added to the rendered HTML for the widget.

    For example, take the following simple form:

    class CommentForm(forms.Form):
    name = forms.CharField()
    url = forms.URLField()
    comment = forms.CharField()

    This form will include three default TextInput widgets, with default rendering - no CSS class, no extra attributes. This means that the input boxes provided for each widget will be rendered exactly the same:

    >>> f = CommentForm(auto_id=False)
    >>> f.as_table()
    <tr><th>Name:</th><td><input type="text" name="name" /></td></tr>
    <tr><th>Url:</th><td><input type="text" name="url"/></td></tr>
    <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>

    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>
    posted on 2009-09-27 15:35 seal 閱讀(3242) 評論(2)  編輯  收藏 所屬分類: Python

    評論

    # re: django form的widgets類型列表 2014-06-27 17:49 HJWAJ
    你這么一貼文檔,你自己還會再看第二遍么。。  回復  更多評論
      

    # re: django form的widgets類型列表 2015-12-18 13:51 企鵝
    額請問請問其味無窮而且  回復  更多評論
      

    主站蜘蛛池模板: 成人免费视频软件网站| 91视频免费观看| 久久久久久久免费视频| 亚洲美免无码中文字幕在线| 久久国产精品萌白酱免费| 亚洲精品国产美女久久久| 中文在线免费不卡视频| 久久青草亚洲AV无码麻豆| 国产99视频精品免费专区| 91大神亚洲影视在线| 波多野结衣中文字幕免费视频| 亚洲中文久久精品无码1| 成人五级毛片免费播放| 国产av无码专区亚洲av毛片搜| 亚洲精品国产高清不卡在线| 中文字幕免费在线看线人动作大片 | 国产精品免费观看视频| 亚洲国产精品VA在线观看麻豆| 午夜视频在线免费观看| 亚洲一卡二卡三卡四卡无卡麻豆| 毛片a级毛片免费播放下载| 成人亚洲国产精品久久| 亚洲熟女少妇一区二区| 1000部免费啪啪十八未年禁止观看| 亚洲日本人成中文字幕| 免费va人成视频网站全| 日韩免费高清播放器| 亚洲人成在线免费观看| 日韩亚洲国产二区| 午夜爽爽爽男女免费观看影院| youjizz亚洲| 久久久久亚洲AV成人网| 国产免费女女脚奴视频网| 国产亚洲蜜芽精品久久| 久久综合图区亚洲综合图区| 免费鲁丝片一级在线观看| 中文字幕久精品免费视频| 亚洲人成自拍网站在线观看| 亚洲国产精品成人精品无码区在线| 午夜精品在线免费观看| 国产白丝无码免费视频|