How to check if the client's browser supports cookies in Django?

84 views
Skip to first unread message

akshat

unread,
Jun 8, 2015, 10:36:47 AM6/8/15
to django...@googlegroups.com
I am making an app which uses User authentication to give access to various pages on the website. I want to use session management for this. But first I need to check if the cookie support is provided by the client's browser. Some conditions which I want to check are - 

1) If the user visits my site first time on the log in page and if the cookie is not supported then the user should not be allowed to login with a message that you should enable cookie support fiirst (Just like Facebook does).

2) User is navigating my site and in between he disables cookie support.Then what should be my course of actions? Should the user be logged out and if not then how to handle it?

Thanks

Larry Martell

unread,
Jun 8, 2015, 10:39:26 AM6/8/15
to django...@googlegroups.com

akshat

unread,
Jun 8, 2015, 10:42:20 AM6/8/15
to django...@googlegroups.com
But this requires two separate views right? How does facebook know on the first attempt that cookie support is not enabled in my browser?

Tom Evans

unread,
Jun 8, 2015, 11:28:11 AM6/8/15
to django...@googlegroups.com
On Mon, Jun 8, 2015 at 3:42 PM, akshat <akshatw...@gmail.com> wrote:
> But this requires two separate views right? How does facebook know on the
> first attempt that cookie support is not enabled in my browser?

It doesn't, it sets a cookie and redirects you to another URL to see
if the cookie is present. You can see this if you inspect the web
traffic to/from your browser using any one of a number of tools, eg
chrome inspector.

"A view" and "a webpage displayed to a user" are not necessarily the
same thing, a view can simply be a piece of code that does something
and redirects the user without displaying a webpage to the user.

Typically, you would not implement this as one view, let alone two -
you would use middleware to set the cookie and redirect, the same
middleware then intercepts the next request and, if they have cookie
support, allow them to access the requested resource, or display a
page indicating that they need cookie support if they do not.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages