【发布时间】:2018-07-07 10:36:16
【问题描述】:
我正在使用烧瓶生成单个网页。
该网页有几个文本框和一个按钮。单击按钮时,我计划在同一页面中显示表格,其中包含从输入中获取的值。
Below is the flask code in python
===========================
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ApplyFilter',methods=['POST','GET'])
def ApplyFilter():
print("Hello")
if request.method == 'POST':
import CompareDataset as cmp
df3= cmp.CompareDataset()
#conver the dataframe to the json objects
AllRecords = json.loads(df3['both'].to_json(orient="records"))
# count the number of records
totalItems = df3['both']["Client"].count()
client=request.form["client"]
account= request.form["account"]
auditstatus = request.form["auditstatus"]
effectivedate=request.form["effectivedate"]
cyclecode=request.form["cyclecode"]
return
jsonify({'data':render_template('ApplyFilter.html',AllRecords=AllRecords,totalItems=totalItems)})
return redirect('/')
snapshot of the html is as below
<td>
<a href=# id=applyfilter><button type="button" class="btn btn-primary active">Apply Filter</button></a>
</td>
</tr>
</table>
</div>
</div>
{% if AllRecords %}
<div class="container-fluid bg-3 text-left">
<div class="counter"><span>Total Records Found : {{ totalItems }}</span></div>
<div "border-bottom: 1px solid #ddd; overflow-y: scroll;" >
<table class="table" style="width: 90%; height: 100%;" >
<thead style="color: #333; background-color: #f1f1f1">
<tr>
<th>Audit Status</th>
<th>Client</th>
<th>Effective Date</th>
<th>Source System Code</th>
<th>Account Number</th>
<th>Cycle Code</th>
<th>AuditTrailtimeStamp</th>
</tr>
</thead>
<tbody>
<tr class="success" >
{% for key,value in AllRecords.iterrows() %}
<td>{{ value["AuditStatusCode"] }}</td>
<td>{{ value["Client"] }}</td>
<td>{{ value["EffectiveDate"] }}</td>
<td>{{ value["SourceSystemCode"] }}</td>
<td>{{ value["InternalAccountId"] }}</td>
<td>{{ value["CycleCode"] }} </td>
<td>{{ value["AuditTrailtimeStamp_x"] }} </td>
{% endfor %}
</tr>
</tbody>
</table>
</div>
</div>
{% endif %}
</form>
The java script tagged to button is as below
$(function() {
$('a#applyfilter').bind('click', function() {
$.getJSON('/ApplyFilter', {
client : $("client").val(),
account : $("account").val(),
auditstatus : $("auditstatus").val(),
auditstatus : $("auditstatus").val(),
effectivedate :$("effectivedate").val(),
cyclecode : $("cyclecode").val(),
}, function(data) {
data = data.data;
});
return false;
});
});
On button click ApplyFilter is getting called. But it is not generating the POST message
127.0.0.1 - - [07/Jul/2018 17:45:40] "GET / HTTP/1.1" 200 - Hello
127.0.0.1 - - [07/Jul/2018 17:45:43] "GET /ApplyFilter HTTP/1.1" 302 -
127.0.0.1 - - [07/Jul/2018 17:45:43] "GET / HTTP/1.1" 200 - Hello
applyfilter 按钮没有生成 post call,因此在路由 Applyfilter 中,if 条件不满足。
请协助并告知我所缺少的内容。
【问题讨论】: