2👍
✅
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
0👍
just you can use the following code inside your view:
if not request.session or not request.session.session_key:
request.session.save()
if the user is anonymous(not logged in user) the session id will created, and you can add your cart items (or anything you want ) in this session , and after the user will logged-in to your system, the session id will remines the same .
i hope this helpful .
👤K.A
- [Answered ]-Django with mongodb using pymongo without using ORM
- [Answered ]-Getting GET in django view
- [Answered ]-Remove trailing data from django timesince — template equivalent
- [Answered ]-Django ManyToManyField delete across models
- [Answered ]-Secure Javascript code
Source:stackexchange.com