創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要介紹django獲取單數(shù)據(jù)的方法,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
本文是總結(jié)Django獲取不同表單的一些方法,希望對大家有幫助。
Django中獲取text,password
名字:<input type="text" name="name"><br><br> 密碼:<input type="password" name="password"> Form表單提交數(shù)據(jù)時使用的是post方式,所以在后端接收參數(shù)的時候需要先判斷請求方式為post時才能請求到數(shù)據(jù) name = request.POST.get('name') password = request.POST.get('password')
Django中獲取單選框
性別:<input type="radio" name="gender" value="man">男 <input type="radio" name="gender" value="woman">女 此時獲取到的值是woman或者man gender = request.POST.get('gender')
Django中獲取單選的復(fù)選框
單選復(fù)選框:<input type="checkbox" name="is_tuanyuan" value="is_tuanyuan">是否是團員 此時如果選中該選項,獲取到的值是value后面的,若沒有選中即是None is_tuanyuan = request.POST.get('is_tuanyuan')
Django中獲取復(fù)選框
復(fù)選框:<input type="checkbox" name="joy" value="sing">唱歌 <input type="checkbox" name="joy" value="dance">跳舞 這里應(yīng)該使用getlist獲取多選框,獲取到的是列表形式,用get獲取只能得到最后一個選項 joy = request.POST.getlist('joy')
Django中獲取單選下拉框
去過哪些城市?單選 <select name="city"> <option>北京</option> <option>天津</option> <option>南京</option> </select> 這里獲取到的就直接是option里面的內(nèi)容 city = request.POST.get('city')
Django中獲取多選的下拉框
去過哪些城市?多選 <select multiple name="more_city"> <option>北京</option> <option>天津</option> <option>南京</option> </select> 這里涉及到多個值得獲取,需要使用getlist,獲取到的是列表,get依然只能獲取到一個值,用戶在使用時按住Ctrl即可以實現(xiàn)多選 more_city = request.POST.getlist('more_city')
Django中獲取文本域
<textarea name="more_text" placeholder="請輸入備注"></textarea> 獲取方法: more_text = request.POST.get('more_text')
以上是django獲取單數(shù)據(jù)的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
網(wǎng)站欄目:django獲取單數(shù)據(jù)的方法-創(chuàng)新互聯(lián)
URL鏈接:http://www.rwnh.cn/article12/cepsdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、品牌網(wǎng)站制作、動態(tài)網(wǎng)站、營銷型網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容