🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC=1,5] >[success] # 常见的交互框 ![](https://box.kancloud.cn/33a1010622e3dfe4caea3722140e0f8c_395x179.png) ~~~ 1. input type="radio" 2. input type="checkbox" 3. input type="file" 4. input type="text" 5. select ~~~ 整体分三类,多选框,文件上传,单选数据 >[danger] ##### 总结 ~~~ 1.单个值返回到后台 "request.POST.get" 2.一组值返回到后台"request.POST.getlist" 3.文件值饭后但后台"request.FILES.get" 4.获取文件名字用"name"属性 5.获取文件内容用"chunks"方法 6.注意的是想要获取文件要在,form表单注明enctype="multipart/form-data ~~~ ![](https://box.kancloud.cn/6cc4851bedf5ce1bb7213b614c6853d4_562x111.png) >[danger] ##### 案例 ---templates 层 ~~~ <form method="post" enctype="multipart/form-data"> <table border="1px" cellspacing="0"> <thead> <th>类型</th> <th>input框</th> </thead> <tbody> <tr> <td>text 类型</td> <td><input type="text" name="texts"></td> </tr> <tr> <td> radio 类型 </td> <td> <input type="radio" name="sex" value="0">男 <input type="radio" name="sex" value="1">女 </td> </tr> <tr> <td> checkbox 类型 </td> <td> <input type="checkbox" value="1" name="habb"> 篮球 <input type="checkbox" value="2" name="habb"> 足球 </td> </tr> <tr> <td> file 类型 </td> <td> <input type="file" name="file"> </td> </tr> <tr> <td>select 类型</td> <td> <select name="city"> <option value="1">北京</option> <option value="2">大连</option> </select> </td> </tr> </tbody> </table> <input type="submit"> </form> ~~~ >[danger] ##### 案例 ---views层 ~~~ def login(request): if request.method == "POST": texts = request.POST.get('texts',None) radio_sex = request.POST.get('sex',None) check_habb = request.POST.getlist('habb',None) select_city = request.POST.get('city') print(texts) print(radio_sex) print(check_habb) print(select_city) file = request.FILES.get('file') print(file.name) with open(file.name,'wb') as f: for i in file.chunks(): f.write(i) return render(request,"index.html") ~~~