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.
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.COOKIESonly contains the key/value mapping of the parsed cookies. Howeverrequest.META['HTTP_COOKIE']contains the raw cookie string which can be parsed by the Pythoncookie.SimpleCookieclass to get themax-agehttp://docs.python.org/library/cookie.html