Django中checkbox复选框的传值问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Sponge_bobo_herbert/article/details/81388337

Django 中,html 页面通过 form 标签来传递表单数据。
对于复选框信息,即 checkbox 类型,点击 submit 后,数据将提交至 view 中的函数。

我们通过request.POST.get() 函数来获取来自 html 页面的值,但是该函数只能 get 到选中的最后一个值。
因此想要传递选中的多个值,需要用 request.POST.getlist() 函数
该函数返回一个列表,可通过迭代来获取列表中每一项的值。

猜你喜欢

转载自blog.csdn.net/Sponge_bobo_herbert/article/details/81388337
今日推荐