【问题标题】:No 'iDisplayStart' key in GET request dictionaryGET 请求字典中没有“iDisplayStart”键
【发布时间】: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 &#34;C:\Python27\lib\site-packages\datatables\datatables.py&#34;, line 102, in run
    self.paging()
  File &#34;C:\Python27\lib\site-packages\datatables\datatables.py&#34;, line 225, in paging
    if (self.request_values[&#39;iDisplayStart&#39;] != &#34;&#34; ) \
  File &#34;C:\Python27\lib\site-packages\webob-1.3.1-py2.7.egg\webob\multidict.py&#34;, line 99, in __getitem__
    raise KeyError(key)
KeyError: &#39;iDisplayStart&#39;

编辑 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


【解决方案1】:

我打错了路线…… 我不小心直接调用了该方法,而不是导航到包含 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 这是将数据返回到表的方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多