重定向后如何从模板中的会话中检索数据。实际上可能吗?
这是我的代码:
查看.py:
if request.POST:
user = request.POST.get('username')
passw = request.POST.get('password')
#password1 = ''
try:
userdata = Employee.objects.get(username = user, password = passw)
user_id = request.session["user_id"] = userdata.id
employee_details = Employee.objects.get(id=user_id)
request.session['emp_details'] = employee_details
return HttpResponseRedirect('/home/')
except Employee.DoesNotExist:
state = "Username or password incorrect !"
return render_to_response('login.html',
{'username' : username1,'state' : state},
context_instance = RequestContext(request))
模板:home.html
<body>
<p>
<ul>
<li><a href="">{{request.session.emp_details.emp_name}}</a></li>
</ul>
</p>
<p><a href="/logout/"><button>logout</button></a></p>
</body>
谢谢