通过 HTTP 重定向发现参数未传递

标签 redirect pyramid

我有一个使用 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/

相关文章:

javascript - 如何重定向到主页

java - 如何在重定向中添加授权 header (Spring Security)

php - 这叫什么,我应该阅读什么才能让它发挥作用?

python - 将滤锅与 Pyramid 应用程序一起使用

python - Web 字体总是从静态路径返回 404

.htaccess - 没有遵循重定向

asp.net - 如何在 ASP.NET 中以编程方式模拟 HTTP POST?

python - Pyramid 和 pyramid_simple 中的 Formencode 来自 : set fixed locale

Python Pyramid PServe 拒绝服务

python - 将 python 列表存储到数据库的最佳方法?