West Tour Road--python full Stack--form component fields and dynamic bindings

Source: Internet
Author: User

One, in HTML | Safe can be processed in the background in the following ways
1 " <input type ' text '/> " 2  from Import Mark_safe 3 Text = Mark_safe (text)
Second, views.py operation
1  fromDjango.shortcutsImportRender2 3  fromDjangoImportForms4  fromDjango.formsImportfields,widgets5  fromApp01ImportModels6 classLoveform (forms. Form):7Price =Fields . Integerfield ()8USER_ID =Fields . Integerfield (9         #widget=widgets. Select (choices=[(1, ' Alex '), (2, ' Xialv '), (3, ' SB '),])Ten         #Database Fetch value Onewidget=widgets. Select () A     ) -     #set up dynamic bindings to update data at any time -     def __init__(self,*args,**Kwargs): the         #super must be in front, copy all the static fields, copy to Self.fields -Super (Loveform,self).__init__(*args,**Kwargs) -self.fields['user_id'].widget.choices = models. UserInfo.objects.values_list ('ID','username') -  + defLove (Request): -obj =Loveform () +     returnRender (Request,'love.html', locals ())

West Tour Road--python full Stack--form component fields and dynamic bindings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.