python submit the form

class the UserForm (forms.Form): 
    username = fields.CharField ( 
        required = True, error_messages, = { ' required ' : ' a user name can not be empty ' }, 
        the widget = widgets.TextInput (attrs = { ' class ' : ' form- Control ' }) 
    )    # regex 
    password = fields.CharField (required = True, error_messages, = { ' required ' : ' a user name can not be empty ' }, 
                                the widget = widgets.TextInput (attrs = {' Class ' : ' form-Control ' }) 
                                ) # regex 
    In Email = fields.EmailField (required = True, error_messages, = { ' required ' : ' a user name can not be empty ' , ' invalid ' : ' E-mail format error ' }, 
                              the widget = widgets.TextInput (attrs = { ' class ' : ' form-Control ' }) 
                              )      # regular expression 
    # ut_id = fields.IntegerField(
    #     required=True,
    #     widget=widgets.Select(attrs={'class':'form-control'},choices=[(1,'普通用户'),(2,'超级用户')])
    # )
    ut_id = fields.IntegerField(
        required=True,
        widget=widgets.Select(
            attrs={'class':'form-control'},
            choices=models.UserType.objects.values_list('id','name')
        )
    )

    ### database updated in real time to solve the problem 
    DEF  __init__ (Self, * args, ** kwargs): 
        . Super (the UserForm, Self) __init__ (* args, ** kwargs) 
        self.fields [ ' ut_id ' ] = .widget.choices models.UserType.objects.values_list ( ' ID ' , ' name ' )

 

Guess you like

Origin www.cnblogs.com/liyongshan/p/11076848.html