python - 'WSGIRequest' 对象没有属性 'cookies'

标签 python django

我正在制作一个网页。有两种看法。 索引详细信息。 在索引中,我使用 response.set_cookie('key', key) 为用户设置 cookie,其中 response = HttpResponseRedirect(file_url)。在 detail 函数中,当我尝试使用

从 cookie 中获取数据时
   if 'key' not in request.cookies:
      key = request.COOKIES['key']  

我收到错误消息:'WSGIRequest' 对象没有属性 'cookies'。 详细错误链接:http://dpaste.com/1P017V6

请帮帮我! 提前致谢。

最佳答案

您键入了 request.cookies,但 cookies 必须大写。试试这个:

if 'key' not in request.COOKIES:

关于python - 'WSGIRequest' 对象没有属性 'cookies',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35318353/

相关文章:

python - Web 抓取到 CSV 的问题 [AttributeError : 'str' object has no attribute 'text]

python - TypeError: 无法在 python 的 SCRAPY 中创建对 'str' 对象的弱引用

python - 如何使用 tf.estimator.DNNClassifier(Scikit Flow?)

加载共享库时出现Python错误: libpython3. 5m.so.1.0:无法打开共享对象文件:没有这样的文件或目录

Django-工厂男孩在一家工厂无缘无故失败

python - 在 Django/Jinja2 模板中将字典对象转换为字符串

python - 使用 API 将图像上传到 GDrive - Python

Python 列表值被覆盖,为什么?

Python/Django - 是否有类似于 Rails 的 assert_difference 的断言?

python - 构建 Lupa 时出错(可能是 pkg-config 的问题)