在GET请求字典中不存在'iDisplayStart'键

2024-05-20 11:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用SqlAlchemy DataTable example作为实现^ {CD1>}的基础。 一切正常,我做了多次屏幕刷新,一切都很完美。现在当我点击刷新时,我突然得到这个错误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表格:

^{pr2}$

编辑

错误来自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'

编辑 这似乎是失败的if声明在数据表.py公司名称:

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”在GET请求字典中不存在


Tags: columnstheinpyselfrequestpagesquery
1条回答
网友
1楼 · 发布于 2024-05-20 11:12:52

我打错路线了。。。。。。 我无意中直接调用了该方法,而没有导航到包含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是指向我的视图的路由,该视图返回包含表和datatable调用的html。 相反,我一直调用127.0.0.1:1234/simple_example,这是将数据返回表的方法

相关问题 更多 >