gpt4 book ai didi

python - 使用 python/GAE 对 cookie 进行存在性检查的最佳方法是什么?

转载 作者:行者123 更新时间:2023-11-30 23:50:11 25 4
gpt4 key购买 nike

在我的代码中我使用

user_id = self.request.cookies.get( 'user_id', '' )

if user_id != '':
me = User.get_by_id( int( user_id ) )

但对我来说,即使它在技术上可行,这看起来也不正确......它看起来不精确。有没有更好的方法可以检查 cookie 是否存在?

最佳答案

我从未使用过 AppEngine,但我猜 request.cookies 只是一个普通的字典对象,例如在 Django 中。您可以尝试以下操作:

if 'user_id' in self.request.cookies:
# cookie exists

关于python - 使用 python/GAE 对 cookie 进行存在性检查的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7297000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com