시험 후 절을 제외하고는이 같은 상황에 매우 편리합니다.
명확하게 말하면 클라이언트에 데이터를 남겨 두어 사용자 세션을 안전하게 추적/관리하는 것과 관련된 다양한 뉘앙스에 접근하지 않습니다.
try:
user_id = self.request.cookies['user_id'] #will raise a 'KeyError' exception if not set.
if isinstance(user_id, basestring):
assert user_id # will raise a 'ValueError' exception if user_id == ''.
try:
user_id = int(user_id)
except ValueError:
logging.warn(u'user_id value in cookie was of type %s and could not be '
u'coerced to an integer. Value: %s' % (type(user_id), user_id))
if not isinstance(user_id, int):
raise AssertionError(u'user_id value in cookie was INVALID! '
u'TYPE:VALUE %s:%s' % (type(user_id), user_id))
except KeyError:
# 'user_id' key did not exist in cookie object.
logging.debug('No \'user_id\' value in cookie.')
except AssertionError:
# The cookie value was invalid!
clear_the_cookie_and_start_again_probably()
except Exception, e:
#something else went wrong!
logging.error(u'An exception you didn\'t count on. Exception: %s' % e)
clear_the_cookie_and_start_again_probably()
raise e
else:
me = User.get_by_id(user_id)
"분명히 말하면 클라이언트에 데이터를 남겨두면 사용자 세션을 안전하게 추적/관리하는 것과 관련된 다양한 뉘앙스에 접근하지 않습니다." 어떻게하면이 뉘앙스를 이해할 수 있을까요? – zakdances
이 페이지의 '클라이언트 측 웹 세션'섹션을 확인하십시오 : http://en.wikipedia.org/wiki/Session_(computer_science). –
AppEngine의 경우 웹 사이트에 따르면 gae 세션을 볼 수 있습니다. "모든 세션 크기에 대해 Google App Engine의 Python 런타임 세션 라이브러리는 매우 빠르고 가볍고 (한 파일) 사용하기 쉬운.". 나는 그것을 직접 사용하고 전혀 문제가 없었습니다. –