Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 复选框烧瓶_Html_Python 3.x_Flask - Fatal编程技术网

Html 复选框烧瓶

Html 复选框烧瓶,html,python-3.x,flask,Html,Python 3.x,Flask,我对表单中的复选框有问题 <form id="form" action="/findPkgInstalled" role="form" method = "POST"> <div class="input-group col-xs-4"> <input type="text" name="pkgSearch" placeholder="Ricerca applicazione non installate.."> <div

我对表单中的复选框有问题

<form id="form" action="/findPkgInstalled" role="form" method = "POST">
    <div class="input-group col-xs-4">
      <input type="text" name="pkgSearch" placeholder="Ricerca applicazione non installate..">
      <div class="input-group-btn">
        <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
      </div>
    </div>
    <h6><input type="checkbox" name="filterName" checked>Filtra per nome</h6>
</form>

但这是行不通的。报告的错误是400个错误请求。我该怎么办?您能帮助我吗?

此错误表示您试图使用不正确的密钥从post请求中获取对象。例如,如果取消选中
filterName
复选框-这将导致此错误:

request.form['filterName']
我的建议是:

0)始终检查帖子正文,以了解可以使用哪些键从此正文检索值

1) 使用

而不是

request.form['filterName']
request.form['filterName'] is 'on'
因为
.get()
返回
None
是因为没有这样的键,而不是在flask中抛出导致400错误的异常

2) 使用

而不是

request.form['filterName']
request.form['filterName'] is 'on'

因为
is
如果两个变量指向内存中的同一对象,则返回True。我不确定进程内存中是否已经有“on”对象

谢谢!我检查request.form.get('filterName')是否为None。。。它起作用了!:)
request.form['filterName'] is 'on'