Django 网站中的 cookie 测试是标准吗?
我是网络开发新手,我正在尝试开发自己的原型。我的代码存在某些参差不齐的边缘。我将把标记跨浏览器兼容、检测客户端浏览器是否打开 JS 以及测试客户端是否启用 cookie 放在一起。
一般问题,但是几乎每个网站都会在其登录视图中测试 cookie 吗?我知道该怎么做,我只是好奇这是否有如此明显的必要。
显然,如果禁用 cookie,身份验证框架将无法工作。如今,客户多久会关闭一次 cookie?
可能是一个天真的问题,或者我可能已经回答了自己,但是嘿,我很好奇。
布伦丹
I'm new to web development and I'm trying to develop my own prototype. There are certain ragged edges with my code. I'll lump together making the markup cross-browser compatible, detecting if JS is turned on for the client browser, and testing if cookies are enabled for client.
General question, but does pretty much every site out there test for cookies within their login view? I know how to do this, I was just curious if it's so blatantly necessary.
Obviously, if cookies are disabled, the auth framework won't work. How often do clients turn off cookies these days?
Might be a naive question or I may have answered myself but hey, I'm curious.
Brendan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cookie 和其他身份验证由会话处理 中间件在姜戈. pylons 文档对 WSGI 如何处理请求/响应以及它们如何从服务器进入代码有更详细的解释此处。
通常在 Django 中,您在视图中使用 @login_required 装饰器,并且 Session 中间件处理实现细节(如您提到的禁用了 cookie 的客户端)。
对于可以放入 cookie 中的其他内容,可以使用 Httprequest.Cookies 数组。
Cookies and other authentication are handled by the session Middleware in Django. The pylons documentation has a bit more detailed explanation of how WSGI handles requests/responses, and how they make their way from the server, up into your code here.
Typically in Django, you use the @login_required decorator in your views, and the Session middleware handles the implementation details (like clients who have cookies disabled, as you mentioned).
For other stuff that you can put in a cookie, you use the Httprequest.Cookies array.