Django 获取表单数据

版权声明:songshao https://blog.csdn.net/qq_35490191/article/details/81294290

       能搜索次问题就说明您对Django的基本配置views的基本写法有所了解我就其他方面的做过都的描述了。

  1. 表单的基本数据类型
    text、password、radio、checkbox、email等;
  2. 如何获取这些类型的数据
    首先在form中需要把method设置为post。然后views文件中,需要用request.POST来获取基本数据
    1)、text、password、radio、email
    都可以用此方法
    name = request.POST.get('name')
    或者
    name = request.POST['name']
    两个方法基本相同都是通过POST请求传输表达数据过来然后用name进行获取数据
    2)、checkbox
    用下面方法
    name = request.POST.getlist('name')
    首先是因为其传参过来是多条数据所有用词方法。

猜你喜欢

转载自blog.csdn.net/qq_35490191/article/details/81294290
今日推荐