0
我正努力在django中訪問我的會話變量。'SessionStore'對象沒有屬性'email'
我有兩個不同的應用程序custom_user和文章。 在我的views.py文件custom_user我已經聲明瞭一個會話變量。
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
request.session['email'] = user.email
return render_to_response(request, "loggedin.html", locals(),context_instance=RequestContext(request))
else:
return HttpResponseRedirect('/accounts/invalid')
和在我的views.py文章應用程序我正在像這樣訪問它。
def articles(request):
return render_to_response('articles.html',
{'articles':Article.objects.all().order_by('-id'),'last':Article.objects.earliest('-pub_date'), 'loggedin':request.session.email})
我的articles.html文件繼承了base.html文件,在那裏我使用{{loggedin}}來訪問變量。 我已經使用{{request.session.email}}但這也不起作用
我最終想要做的是顯示我的網站在我的導航欄中登錄的用戶的電子郵件地址.html文件。
我只在用auth_view函數呈現的loggedin.html文件中獲取user.email值。但不在任何其他html文件中。