Python - Django - form components common fields and field parameter

mailbox:

views.py:

from django import forms
from django.forms import widgets


class RegForm(forms.Form):
    email = forms.EmailField(
        label="邮箱",
        widget=widgets.EmailInput(),
    )

 

single button:

views.py:

Import Django Forms from 
from `` django.forms`` Import Widgets 


class regform (forms.Form): 
    Hobby = forms.ChoiceField ( 
        choices = ((. 1 "basketball"), (2, "football"), (3 "badminton") ), option # 
        label = "hobby", 
        Initial = 2, the default selection # 2 
        the widget = widgets.RadioSelect () # set radio buttons 
    )

operation result:

 

 

Radio (default):

views.py:

Import Django Forms from 
from `` django.forms`` Import Widgets 


class regform (forms.Form): 
    Hobby = forms.ChoiceField ( 
        choices = ((. 1 "basketball"), (2, "football"), (3 "badminton") ), option # 
        label = "hobby", 
        Initial = 2, the default selection # 2 
        the widget = widgets.Select () # write did not write all the same 
    )

operation result:

 

 

Multiple choice:

views.py:

Import Django Forms from 
from `` django.forms`` Import Widgets 


class regform (forms.Form): 
    Hobby = forms.MultipleChoiceField ( 
        choices = ((. 1 "basketball"), (2, "football"), (3 "badminton") , (4, "volleyball")), option # 
        label = "hobby", 
        Initial = [2, 4], the default selection # 2, 4 
        the widget = widgets.SelectMultiple () # set to multi-select 
    )

operation result:

 

 

Individual check boxes:

views.py:

Django Import Forms from 
from `` django.forms`` Import Widgets 


class regform (forms.Form): 
    rem_pwd = forms.ChoiceField ( 
        label = "Remember password", 
        Initial = "the checked", #, selected by default 
        widget = widgets.CheckboxInput () # set individual check box 
    )

operation result:

 

 

Multiple choice check boxes:

views.py:

Import Django Forms from 
from `` django.forms`` Import Widgets 


class regform (forms.Form): 
    rem_pwd = forms.MultipleChoiceField ( 
        choices = ((. 1 "basketball"), (2, "football"), (3 "badminton") , (4, "volleyball")), option # 
        label = "hobby", 
        Initial = [. 1,. 3], 
        the widget widgets.CheckboxSelectMultiple = () # to multiple choice box 
    )

operation result:

 

Guess you like

Origin www.cnblogs.com/sch01ar/p/11470332.html