2014-12-27 4 views
-1

나는 현재 작업하고있는 프로젝트가 있습니다. 사용자가 로그인 할 때 쿠키를 설정하여 기억하도록하고 싶습니다. 그러나 나는 인터넷에서 모든 방법을 시도했다. Google에서 Stack Overflow까지. 나는 단지 작동하지 않는 방법을 찾는 것처럼 보인다. 내가 시도Python을 사용하여 브라우저에 쿠키 설정

:

class Main(webapp2.RequestHandler): 
    def get(self): 
     print "Set-Cookie: testing=test123cookie" 
     print "Content-Type: text/html\n" 

그리고 didnt가 작동합니다. 다음 시도 :

import Cookie 

class Main(webapp2.RequestHandler): 
    def get(self): 
     cookie = Cookie.SimpleCookie() 
     cookie['lastvisit'] = "test" 
     print cookie 
     print 'Content-Type: text/html\n' 

놀랍게도, 놀랍지 만, 그것은 작동하지 않습니다. 나는 무엇을해야합니까? 어떻게해야합니까? 나는 바보 같이 행동하고 올바르게 행동하지 않을 것이라고 확신한다.

감사합니다.

답변

1

당신은 set_cookie() method를 사용해야합니다 :

class Main(webapp2.RequestHandler): 
    def get(self): 
     self.response.set_cookie('lastvisit', 'test', max_age=360, path='/') 
+0

덕분에이 일했다. 마침내! – ZeroByter

+0

그리고 쿠키를 검색하려면 :'self.request.cookies.get ("lastvisit")'(http://stackoverflow.com/q/11816196/328817 참조). – Sam