Skip to main content
 首页 » 编程设计

python之从 Bootstrap button> 接收 HTML 请求

2024年11月01日12mfrbuaa

<form method="post" class="form-horizontal" role="form"> 
    <div class="btn-group col-sm-3"> 
        <button id="typeSelect" type="button" name="reportType" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> 
            People <span class="caret"></span> 
        </button> 
        <ul class="dropdown-menu" role="menu"> 
            <li> 
                ... 
            </li> 
            ... 
        </ul> 
    </div> 
 
    <div class="form-group"> 
        <label for="inputName" class="col-sm-2 control-label">Name</label> 
        <div class="col-sm-3"> 
            <input type="text" class="form-control" id="inputName" placeholder="Name" name="name" value="{{name}}" onblur="isEmpty(this)"> 
        </div> 
    </div> 
</form> 

我的表单中有两个输入,我正尝试在我的 Python 代码中获取输入。

    report_type = self.request.get('reportType') 
    name = self.request.get('name') 

name 工作正常,但 report_type 将始终为 None。
在按钮 (Bootstrap) 中检索选择的正确方法是什么?

请您参考如下方法:

根据button element specifications :

A button (and its value) is only included in the form submission if the button itself was used to initiate the form submission.

您将不得不寻找另一种方法来传递按钮的值。例如,您可以将值存储在隐藏字段中。