간단한 if 문을 사용하지 않는 이유는 무엇입니까? 최소 허용 값이 7
이고 최대 허용 값이있는 경우
예를 들어, 47
당신이 쓸 수 :
def post(self):
my_arg = self.get_argument('my_arg')
if not 7 <= my_arg <= 47:
raise tornado.web.HTTPError(400) # 400 Bad Request
을이 많은 일을하는 경우와 같은 방법을 재정의하는 시도 할 수 있습니다 :
class MyHandler(tornado.web.RequestHandler):
def get_argument(self, name, minimum, maximum):
argument = super(MyHandler, self).get_argument(name)
if not minimum <= argument <= maximum:
raise tornado.web.HTTPError(400) # 400 Bad Request
return argument
def post(self):
small_arg = self.get_argument('small_arg', 1, 3)
medium_arg = self.get_argument('medium_arg', 7, 47)
large_arg = self.get_argument('large_arg', 9001, 10000)
부담없이 다른 HTTP Status Code을 선택하십시오.