0

我在视图中将会话变量设置为:

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,})

比在我的上下文处理器函数中,我想获得这个会话变量的值。我怎样才能做到这一点?

我努力了:

#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}
4

1 回答 1

2

您应该能够通过request.session在上下文处理器中使用来访问会话。

#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}
于 2013-05-10T11:51:55.227 回答