Issue
Hi I want to enable session for anonymous user in Django. When i Log in i can see a session id in cookie. But when i log out there is no session id. I want to use the cookie to store some cart data.
I want to create a session object in which i want to store the data of products an anonymous user adds to the cart. Also i want the same session object to persist when a user logs in after adding items to cart. so that he can checkout.
I can add or retrieve data from a session object but i couldn't figure out how to create a session object for an anonymous user.
How to do this?
Solution
if not request.user.is_authenticated():
# create your session data for anonymous user
but I would not save cart data into session. I would save them into database
Answered By - doniyor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.