我有一个使用 URL 调度的 Pyramid 应用程序。我有一条路线“/delete”,它从数据库中删除一条记录并重定向到 View 。当重定向发生时,我希望 View 在同一页面上重新加载。我正在使用 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 :
@view_config(route_name='records', renderer='records.jinja2')
def records(request):
# Get the current page
current_page = int(request.params.get('page', 1))
加载记录 View 时,不会传递参数,并为 current_page 设置默认值“1”。 app_name 和 user_id 的“BLAH”值也不会传递。
我注意到的一件事是, View 似乎加载了两次,但我不知道如何确认。我认为该页面加载了两次,因为我在重定向后看到对数据库的两次调用。
我错过了什么?谢谢。
最佳答案
删除路由中的print url
时的url是什么以及路由记录
定义是什么?
如果您想要 GET Request ,你应该尝试关键字参数 _query
url = request.route_url(name='records', _query=(('page', current_page),))
关于通过 HTTP 重定向发现参数未传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20254620/