【发布时间】:2017-07-16 16:04:22
【问题描述】:
我正在尝试在我的 Flask 应用程序上使用来自 sqlite 的数据来实现服务器端处理。我是新手,所以我不知道出了什么问题。到目前为止,我已经做到了:
HTML:
<table id="myTable" class="table table-striped" style="width:100%" >
<thead>
<tr>
<th>Time</th>
<th>Mean Current</th>
<th>Vapour Pressure</th>
<th>Mean Voltage</th>
<th>Temperature</th>
<th>Humidity</th>
<th>Bar Pressure</th>
<th>RPM</th>
<th>Wind Sector</th>
<th>Wind Speed</th>
<th>Air Density</th>
<th>DC Voltage</th>
<th>Power Sector</th>
<th>Furling Angle</th>
<th>Yaw angle</th>
</tr>
</thead>
</table>
Javascript:
$(document).ready(function() {
$('#myTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "/page_test"
} );
});
查看功能:
@app.route('/page_test')
def page_test():
data = json.dumps(meas[2])
print data
return data
meas[2] 是我的字典:
[dict((c.description[i][0], value) \
for i, value in enumerate(row)) for row in c.fetchall()]
在“打印数据”中,所有内容都打印得很好,如下所示:
{"MeanCurrent": 0.05933, "Temperature": 15.095, "YawAngle": 0.0, "MeanVoltage": 0.67367, "VoltageDC": 3.18309, "PowerSec": 0.06923, "FurlingAngle": -0.2266828184, "WindSpeed": 1.884, "VapourPressure": 1649.25948, "Humidity": 0.4266, "WindSector": 0, "AirDensity": 1.23051, "BarPressure": 1020.259, "time": "2015-04-22 20:58:28", "RPM": 0.0, "ID": 1357}
这是乘以行数。
但是,当我运行应用程序并插入查询时,表格只显示<th> 标记,并且在表格顶部写有 "Processing..."显示的数据。在我的烧瓶应用程序的终端,显示了一个巨大的字符串,这是一个小示例:
/page_test?draw=2&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5
这是一个截图:
每次我单击th 标签时,都会再次出现相同的字符串。似乎我错过了一些重要的东西,但由于这是我的第一个应用程序,我无法弄清楚它是什么。任何有关修改代码的建议将不胜感激。
【问题讨论】:
-
我也有同样的问题。你解决了吗?
标签: python json flask datatables server-side-scripting