如何显示django-cookie的到期时间? [英] How to display the expiration time of django-cookie?
问题描述
在我的 getCookie
函数中,我想显示名称和给定的cookie的过期时间,但我能够归档的是名称
In my getCookie
function, I'd like to display the name AND the expiration-time of given cookie, but all I've been able to archive is the name of it, as a string.
Cookie已设置,并按预期到期,我只想以简单的方式显示剩余时间。
The cookie is set, and expires as expected, I'd just like to show the remaining time of it, in a simple way.
def setCookie(request):
cook = HttpResponseRedirect('/getCookie/')
cook.set_cookie('theCookie', value='Dough', max_age=15)
return cook
def getCookie(request):
s=""
if request.COOKIES.has_key('theCookie'):
s += request.COOKIES['theCookie']
#s += request.COOKIES['theCookie'].expires..? HERE?
else:
s="Sorry, your cookie has expired"
return HttpResponse(s)
推荐答案
request.COOKIES
仅包含解析的Cookie的键/值映射。 request.META ['HTTP_COOKIE']
包含可以由Python cookie.SimpleCookie
解析的原始Cookie字符串,类获取 max-age
http:/ /docs.python.org/library/cookie.html
request.COOKIES
only contains the key/value mapping of the parsed cookies. However request.META['HTTP_COOKIE']
contains the raw cookie string which can be parsed by the Python cookie.SimpleCookie
class to get the max-age
http://docs.python.org/library/cookie.html
这篇关于如何显示django-cookie的到期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!