开发者

Is testing for cookies in a Django website standard?

开发者 https://www.devze.com 2023-02-26 15:38 出处:网络
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 t

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消