나는 토네이도에 새로운 오전, 나는이 질문의 목적이 단순화 된 코드를 가지고 :Tornado/Python -이 반복을 피하려면 어떻게해야합니까?
class LoginHandler(BaseHandler):
def get(self):
error_message = None
title = "Log in to your account"
self.render("login.html", error_message=error_message, title=title)
def post(self):
#function and params excluded for brevity of question
error_message = self.authenticate_user()
title = "Log in to your account"
self.render("login.html", error_message=error_message, title=title)
self.render("login.html", error_message=error_message, title = title)
뿐만 아니라 제목 변수 "(겉으로는 불필요), 그렇지 않으면 때문에, 나는 오류가 반복 글로벌 변수 '제목'또는 'ERROR_MESSAGE는'하지 내가 페이지를 렌더링하는 post
또는 get
사용 여부에 따라 "정의.
LoginHandler
) 작동 하나
title
변수와 하나의
self.render("login.html"...)
페이지 당 핸들러를 가질 수 있는지 궁금 할 때 중 하나를 얻을 또는 포스트 함수가 호출된다. 축 어적 반복을 좋아하지 않지만 두 기능 모두에서 동일한 작업을 수행하지 않으면 오류 메시지를 피하는 데 문제가 있습니다.
어떻게 해결할 수 있습니까? 고맙습니다.
대단합니다. 고맙습니다. 다행히 나는 마크로부터 뭔가를하지 않고 있었다. – JohnZ