【发布时间】:2014-09-22 10:30:16
【问题描述】:
我使用SqlAlchemy DataTable example 作为我尝试实现DataTables 的基础。
一切正常,我进行了多次屏幕刷新,一切正常。现在,当我单击刷新时,我突然收到此错误KeyError: 'iDisplayStart'。我没有改变任何东西,或者至少我是这么认为的。这是我的python方法
@view_config(route_name='simple_example', request_method='GET', renderer='json')
def simple_example(request):
# defining columns
columns = []
columns.append(ColumnDT('ixTransformerTurnsRatio'))
columns.append(ColumnDT('iPrimaryVoltage'))
columns.append(ColumnDT('iSecondaryVoltage'))
columns.append(ColumnDT('sTap'))
columns.append(ColumnDT('decRatioA'))
columns.append(ColumnDT('decExcitationA'))
columns.append(ColumnDT('decDeviationA'))
columns.append(ColumnDT('decRatioB'))
columns.append(ColumnDT('decExcitationB'))
columns.append(ColumnDT('decDeviationB'))
columns.append(ColumnDT('decRatioC'))
columns.append(ColumnDT('decExcitationC'))
columns.append(ColumnDT('decDeviationC'))
# defining the initial query depending on your purpose
query = DBSession.query(TTransformerTurnsRatio)
# instantiating a DataTable for the query and table needed
rowTable = DataTables(request, TTransformerTurnsRatio, query, columns)
# returns what is needed by DataTable
return rowTable.output_result()
这是我的表格 html:
<table class="table" id="simple-example">
<thead>
<tr>
<th>ID</th>
<th>PV</th>
<th>SV</th>
<th>Tap</th>
<th>Ratio A</th>
<th>Excitation A</th>
<th>Deviation A</th>
<th>Ratio B</th>
<th>Excitation B</th>
<th>Deviation B</th>
<th>Ratio C</th>
<th>Excitation C</th>
<th>Deviation C</th>
</tr>
</thead>
<tbody></tbody>
</table>
编辑
错误来自datatables.py 中的paging() 方法。
File "C:\Python27\lib\site-packages\datatables\datatables.py", line 102, in run
self.paging()
File "C:\Python27\lib\site-packages\datatables\datatables.py", line 225, in paging
if (self.request_values['iDisplayStart'] != "" ) \
File "C:\Python27\lib\site-packages\webob-1.3.1-py2.7.egg\webob\multidict.py", line 99, in __getitem__
raise KeyError(key)
KeyError: 'iDisplayStart'
编辑 datatables.py 中的 if 语句似乎失败了:
def paging(self):
"""Construct the query, by slicing the results in order to limit rows showed on the page, and paginate the rest
"""
pages = namedtuple('pages', ['start', 'length'])
if (self.request_values['iDisplayStart'] != "" ) \
and (self.request_values['iDisplayLength'] != -1 ):
pages.start = int(self.request_values['iDisplayStart'])
pages.length = int(self.request_values['iDisplayLength'])
offset = pages.start + pages.length
self.query = self.query.slice(pages.start, offset)
在我看来,GET 请求字典中不存在“iDisplayStart”
【问题讨论】:
-
突然出现
which错误? -
标题中的错误
-
能否提供完整的追溯信息?
-
我会添加到“编辑”下
标签: jquery python datatables jquery-datatables pyramid