【问题标题】:Cookies getting lost after the redirect (Bottle + uWSGI + Python)重定向后 Cookie 丢失(Bottle + uWSGI + Python)
【发布时间】:2025-12-30 22:55:11
【问题描述】:

我使用 Bottle 框架和 uWSGI 应用服务器来托管我的网站。我现在正在更改网站上的主要编程语言(PHP-> Python)并且遇到了问题:我刚刚使用bottle.response.set_cookie() 设置的cookie 在重定向后消失了。所以完整的代码是:

# Login page (/login)
from bottle import redirect, response # etc
...
...
response.set_cookie('cool', 'cookie') # Works good without redirect
redirect('/') # Cookie disappears 

我知道这个问题可能会出现,就在这里。我对 PHP 没有这个问题。 我需要设置一个 cookie,然后将用户重定向到主页。有什么办法可以正确地做到这一点吗?

UPD:

问题的临时解决方案是降级到 0.11.2。

【问题讨论】:

    标签: python cookies uwsgi bottle


    【解决方案1】:

    也许您正在使用受此错误影响的版本:

    https://github.com/defnull/bottle/issues/386

    【讨论】:

    • 从该链接:redirect() 创建一个新的 HTTPResponse 并替换全局响应对象上定义的标头或 cookie。这是正确的行为。我使用的是最新的 0.12-dev。