how store list in django session
if not 'saved' in request.session or not request.session['saved']:
request.session['saved'] = [obj]
else:
saved_list = request.session['saved']
saved_list.append(obj)
request.session['saved'] = saved_list
how store list in django session
if not 'saved' in request.session or not request.session['saved']:
request.session['saved'] = [obj]
else:
saved_list = request.session['saved']
saved_list.append(obj)
request.session['saved'] = saved_list
django sessions for beginners
def index(request):
...
num_authors = Author.objects.count() # The 'all()' is implied by default.
# Number of visits to this view, as counted in the session variable.
num_visits = request.session.get('num_visits', 0)
request.session['num_visits'] = num_visits + 1
context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
'num_visits': num_visits,
}
# Render the HTML template index.html with the data in the context variable.
return render(request, 'index.html', context=context)
how to get data from django session
######### Store the data ############
request.session['idempresa'] = profile.idempresa
######## now use the data ################
if 'idempresa' in request.session:
idempresa = request.session['idempresa']
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us