长话短说,所以我尝试使用“POST”来获取我的 Flask 模板中的复选框值。但是,我在模板中的数据表(数据表按钮)中使用了一些动态表。这些数据表导致我的发布请求不起作用。 (在不使用数据表的情况下,如果它只是一个很长的常规表,那么我的发布请求将起作用)
将 DataTable Checkboxes 值解析为 POST 请求的正确方法是什么?有谁知道我的数据表定义有什么问题?
非常感谢!
在烧瓶中:
def project():
if request.method=="POST":
selected_tags=request.form.getlist('table_records')
带 Flask 模板的 HTML:
<form action="" method="post">
<button type="submit" name="Compare" value="Compare" class="btn-link">Compare</button>
<table id="datatable-buttons" class="table table-striped table-bordered bulk_action">
<thead>
<tr>
<th><input type="checkbox" id="check-all" class="flat"></th>
<th>Tag</th>
<th>Release date</th>
<th>Number of Blocks</th>
</tr>
</thead>
{% for each_run in all_runs %}
<tr>
<td><input type="checkbox" class="flat" name="table_records[]" value="{{each_run.tag}}"></td>
<td class=" "><a href= "{{url_for('skybolt_synthesis_tag',tag=each_run.tag)}}"> {{each_run.tag}}</a></td>
<td>{{each_run.start_time}}</td>
<td>{{block_count[each_run.tag]}}</td>
</tr>
{% endfor %}
</form>
数据表组件
$(document).ready(function() {
var handleDataTableButtons = function() {
if ($("#datatable-buttons").length) {
$("#datatable-buttons").DataTable({
dom: "Bfrtip",
buttons: [
{
extend: "copy",
className: "btn-sm"
},
{
extend: "csv",
className: "btn-sm"
},
{
extend: "excel",
className: "btn-sm"
},
{
extend: "pdfHtml5",
className: "btn-sm"
},
{
extend: "print",
className: "btn-sm"
},
],
responsive: true
});
}
};
}