通过HTTPFound参数重定向未传递

时间:2013-11-27 22:50:19

标签: redirect pyramid

我有一个使用URL disptach的Pyramid应用程序。我有一个'/ delete'路由,它从数据库中删除一条记录并重定向到一个视图。当重定向发生时,我希望视图在同一页面上重新加载。我正在使用webhelpers.paginate进行分页。问题是,当重定向发生时,参数不会传递。

删除路线:

@view_config(route_name='delete')
def delete(request):
    # Get the current page, the page title, and the id of the record to delete
    current_page = int(request.params.get('page', 1))

    # Database transactions
    ...
    # Reload the view
    url = request.route_url(route_name='records', app_name='BLAH', userid='BLAH', page=current_page)
    return HTTPFound(location=url)

记录视图:

@view_config(route_name='records', renderer='records.jinja2')
def records(request):
    # Get the current page
    current_page = int(request.params.get('page', 1))

加载记录视图时,不传递参数,并为current_page设置默认值“1”。 app_name和user_id的“BLAH”值也不会传递。

我注意到的一件事是看起来两次加载视图但我不知道如何确认。我认为页面加载了两次,因为我看到重定向后对数据库的两次调用。

我错过了什么?感谢。

1 个答案:

答案 0 :(得分:2)

删除路线中的print url及路线records的定义是什么时,网址是什么?
如果您想获得GET Request,请尝试使用关键字参数_query

url = request.route_url(name='records', _query=(('page', current_page),))