使用 Djangologout
当用户注销时,所有会话值都会被刷新。
即使用户注销,我也有办法保留一些会话值吗?
您可能希望使用 cookie 而不是 session 来实现此目的。
# views.py, login view
# After you have authenticated a user
username = 'john.smith' # Grab this from the login form
# If you want the cookie to last even if the user closes his browser,
# set max_age to a very large value, otherwise don't use max_age.
response = render_to_response(...)
response.set_cookie('the_current_user', username, max_age=9999999999)
在您的登录视图中:
remembered_username = request.COOKIES.get('the_current_user', '')
将上面的内容push到模板中即可显示:
Hello {{ remembered_username }}
参考:http://docs.djangoproject.com/en/1.2/ref/request-response/#django.http.HttpResponse.set_cookie
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)