zoukankan      html  css  js  c++  java
  • Django框架获取各种form表单数据

    Django中获取textpassword

      名字:<input type="text" name="name"><br><br>

      密码:<input type="password" name="password">

      Form表单提交数据时使用的是post方式,所以在后端接收参数的时候需要先判断请求方式为post时才能请求到数据

      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中获取单选的复选框

      单选复选框:<input type="checkbox" name="is_tuanyuan" value="is_tuanyuan">是否是团员

      此时如果选中该选项,获取到的值是value后面的,若没有选中即是None

      is_tuanyuan = request.POST.get('is_tuanyuan')

    Django中获取复选框

      复选框:<input type="checkbox" name="joy" value="sing">唱歌

          <input type="checkbox" name="joy" value="dance">跳舞

      这里应该使用getlist获取多选框,获取到的是列表形式,用get获取只能得到最后一个选项

      joy = request.POST.getlist('joy')

    Django中获取单选下拉框

      去过哪些城市?单选

      <select name="city">

        <option>北京</option>

        <option>天津</option>

        <option>南京</option>

      </select>

      这里获取到的就直接是option里面的内容

      city = request.POST.get('city')

    Django中获取多选的下拉框

      去过哪些城市?多选

      <select multiple name="more_city">

        <option>北京</option>

        <option>天津</option>

        <option>南京</option>

      </select>

      这里涉及到多个值得获取,需要使用getlist,获取到的是列表,get依然只能获取到一个值,用户在使用时按住Ctrl即可以实现多选

      more_city = request.POST.getlist('more_city')

    Django中获取文本域

      <textarea name="more_text" placeholder="请输入备注"></textarea>

      获取方法:

      more_text = request.POST.get('more_text')

  • 相关阅读:
    java.io.FileNotFoundException: D:workspacegbrmWebRoot空缺职位列表20140414093026.xls (系统找不到指定的路径。)
    select * from (select t.*,rownum as rowno from (select * from j_kqzw where 1=1 and DEADLINE >='2013-04-14' and DEADLINE <='2014-04-14' ) t)where rown
    hibernate的映射文件字段长度和数据库里面的字段长度
    八门神器
    计算机
    c语言
    捕鱼达人
    桂林力港网络科技有限公司
    cocos2d-x
    3gp 编辑
  • 原文地址:https://www.cnblogs.com/lutt/p/10638161.html
Copyright © 2011-2022 走看看