typeerror while retriving cookies in web2py
var websites = new Array("http://www.abc.com","http://www.123.com");
//i am writin cookies like this in javascript in view
var web=websites[1] ;
var exdate=new Date();
exdate.setDate(exdate.getDate() + 24);
var visit= web +" ;expires= "+ exdate.toUTCString();
document.cookie= "mycookie =" + visit;
now while retriving it in controller
print request.cookies
i can see my cookies is there
if request.cook开发者_JAVA百科ies.has_key("mycookie"):#geting true
value=request.cookies("mycookie").value
giving me exception <type 'exceptions.TypeError'>
why?
In this case request.cookies
is a dictionary, so you must access it as such. As you did:
value=request.cookies("mycookie").value
This is treating request.cookies
as a function, which is why you get a TypeError since it is not a function. To access a value in a dictionary given the key, you can use:
value=request.cookies["mycookie"].value
精彩评论