Django Accessing Session Variable from within Context_Processor function -
i setting session variable inside view as:
def festival_theme(request, year, month, day, slug): festival = project.objects.get(category__name=__('festival'), slug=slug) request.session['_active_festival_id'] = festival.id return render(request, 'web/festival/theme.html', {'festival':festival,}) than inside context processor function want session variable's value. how can achieve this?
i have tried:
#context_processors.py def festivals(request): s = sessionstore() activefestivalid = s['_active_festival_id'] allfestivals = project.objects.filter(category__name='festival').order_by('-date') return {'allfestivals':allfestivals}
you should able access session using request.session in context processor.
#context_processors.py def festivals(request): activefestivalid = request.session.get('_active_festival_id', none) allfestivals = project.objects.filter( category__name='festival').order_by('-date') return {'allfestivals': allfestivals}
Comments
Post a Comment