我使用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>
修改
错误来自paging()
中的datatables.py
方法。
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)
在我看来,iDisplayStart&#39;不存在于GET请求字典
中答案 0 :(得分:0)
我说的是错误的路线...... 我不小心直接调用了该方法,而不是导航到包含ajax调用的页面
这些是我的路线:
config.add_route('simple_example', '/simple_example')
config.add_route('test', '/test')
@view_config(route_name='test', renderer='templates/main.html')
def test(request):
partial = ["Custom/test.html"]
return dict(partial=partial)
test是我的视图的路径,它返回包含表和数据表调用的html。 相反,我一直调用127.0.0.1:1234/simple_example,这是将数据返回到表中的方法