我是一名新手,正在尝试在我的Flask应用程序中使用来自sqlite的数据来实现服务器端处理。我无法弄清楚问题出在哪里。到目前为止,我已经做到了这一点:
HTML:
JavaScript:
在“打印数据”中,一切都打印得很好,就像这样:
这将乘以行数。
然而,当我运行应用程序并插入查询时,表格仅显示
<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]
is my dict:
[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...",没有显示任何数据。在我的flask应用程序终端上,显示了一个巨大的字符串,以下是其中的一小部分:/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
标签时,都会再次出现相同的字符串。看起来我错过了一些重要的东西,但由于这是我的第一个应用程序,我无法弄清楚它是什么。欢迎对代码进行修改的任何建议。