안녕하세요 장고/파이썬 초보자입니다. 아래 코드를 이해하는 데 도움이 필요합니다. 내가 혼란 스러워요django 문서 코드 이해 - 세션
def post_comment(request, new_comment):
if request.session.get('has_commented', False):
return HttpResponse("You've already commented.")
c = comments.Comment(comment=new_comment)
c.save()
request.session['has_commented'] = True
return HttpResponse('Thanks for your comment!')
는 request.session.get ('has_commented'거짓) 사용자가 the'has_commented 주석 경우 경우에있다 '키가 true로 설정되어있는, 그래서 당신은 있는지 확인을 wouldnt' has_commented '가 true로 설정되어 사용자가'has_commented '가 false인지 확인하는 대신 다른 설명을 게시하지 않도록합니다. 내 논리가 맞지 않아? 또한 세션 키 'has_commented'의 출처는 어디입니까?
. 'False'는 키가 사전에없는 경우 반환되는 값입니다. – akaIDIOT