Django Framework input text box radio box multiple box upload file data transfer background program request.getlist receive multiple results obj.chunks for file transfer enctype= "Multipart/form-data file Transfer Mandatory header

Source: Internet
Author: User

In the previous blog, we learned that if we create Django, here we mainly talk about how to pass data to the background

In the URL file, import views from app01 and create URLs (R ' ^login/', views.login)

 from Import Admin  from Import URL  from Import     = [url (r ' ^admin/', admin.site.urls),        URL (r'^login/', Views.login),]

Next, the login function in the app01.views operation

Brief description: When the first time to enter Views.login is get, so only need to do a jump to login.html

When the login.html submits the form back to Views.login, the way is post, which distinguishes the two by the IF statement

 fromDjango.shortcutsImportRender#Create your views here.defLogin (Request):
#第一次直接跳转到login. html, waiting for the user's actionifRequest.method = ='GET': Render (Request,'login.html') elifRequest.method = ='POST': #接收用户返回时的操作
#接收name = value information in ' Gender '#gender = Request. Post.get (' Gender ') #Print (gender)


#接收name = value information in ' Gender ', getlist is often used to receive multiple messages, such as multi-marquee#gender = Request. Post.getlist (' Gender1 ') #Print (gender)



#City = Request. Post.get (' City ') #Print (city)
# request. Files.get is primarily used to receive Name= ' Fafa ' files
Chunks fragment of #用循环的方式接收 file
        Import OS
        obj = Request. Files.get ('fafa')        print(obj)
=obj.name = open (File_path, mode='wb') for in obj.chunks (): f.write (i) f.close () return' login.html ')

HTML file, note that you need to include the file in the form when you transfer it

Enctype= "Multipart/form-data"

The name is the same when passing the single-select multiple-selection drop-down box, which is distinguished by the difference in value.

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Title</title></Head><Body>    <formAction= "/login/"Method= "POST"enctype= "Multipart/form-data">        <P>        <inputtype= "text"name= "username">        <inputtype= "text"name= "pwd">        <inputtype= "text"name= "Email">        </P>        <P>Male:<inputtype= "Radio"name= "Gender"value= "1">female:<inputtype= "Radio"name= "Gender"value= "2">Publicity:<inputtype= "Radio"name= "Gender"value= "3">        </P>        <P>Male:<inputtype= "checkbox"name= "Gender"value= "One">female:<inputtype= "checkbox"name= "Gender"value= "All">Publicity:<inputtype= "checkbox"name= "Gender"value= " the">        </P>        <P>            <Selectname= "City">                <optionvalue= "sh">Shanghai</option>                <optionvalue= "XM">Xiamen</option>                <optionvalue= "GJ">Guangzhou</option>            </Select>        </P>        <P>            <inputtype= "File"name= "Fafa">        </P>        <inputtype= "Submit"value= "Submit">    </form></Body></HTML>

Django Framework input text box radio box multiple box upload file data transfer background program request.getlist receive multiple results obj.chunks for file transfer enctype= "Multipart/form-data file Transfer Mandatory header

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.