【问题标题】:Redirecting to a url with POST data using Python Bottle使用 Python Bottle 重定向到带有 POST 数据的 url
【发布时间】:2014-01-31 23:49:27
【问题描述】:

有没有办法在重定向到另一个页面时添加 POST 数据?

我已经构建了一个服务,它将用户重定向回调用该服务时指定的任何页面。问题是由于复杂且编写错误的重写规则等,我无法在 url 上放置任何 GET 参数,因此我需要使用 POST 发送一个值。是否有添加到 Bottles 重定向(return_url)或在 Python 中使用其他库?

【问题讨论】:

    标签: python redirect bottle


    【解决方案1】:

    你可以构建response,而不是使用bottle的redirect(url)方法

    from bottle import route, run, response
    
    @post('/wrong')
    def wrong():
      response.status = 303
      response.set_header('Location', '/hello')
      return '"key":"val"'  # Enter the body here
    
    @route('/hello')
    def hello():
      return "Hello World!"
    
    run(host='0.0.0.0', port=8080, debug=True)
    

    【讨论】:

    • 简单的 WSGI 服务器确实有一些限制,例如,如果您将重定向作为钩子,当套接字被中断时,日志消息会中断。使用 CherryPy,然后效果很好。
    猜你喜欢
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 2020-07-23
    • 2015-02-05
    • 2014-05-07
    相关资源
    最近更新 更多