在我的代码中我使用
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/