강의

멘토링

커뮤니티

Inflearn Community Q&A

immutable000's profile image
immutable000

asked

[Renewal] Introduction to Python Backend and Web Technology for Beginners (Python Intermediate, Understanding Backend and Web Technology Basics with Flask) [Full Stack Part1-1]

Python Intermediate Grammar for Flask Deep Dive: Python Decorator 2

안녕하세요 강의를 보다가 궁금한게 있어서 글 썻습니다!

Written on

·

276

0

6분~7분에 설명하신 인자가 있는 데코레이터를 설명해 주실때

def func (num)

   def outter_func(func)

      def inner_func ( ... )

이 구조를 설명해주셨는데 

제가 저런 파라미터를 사용한 데코레이터 사용한 예시가 궁금해서 flask에 있는 scaffold.py 를 확인해봤습니다!

https://github.com/pallets/flask/blob/main/src/flask/scaffold.py

 

scaffold 클래스내에 route 메소드는 위에 설명한 구조가 아닌

 

def route(self, ...)

     def decorator ( func)

이런 2중구조더라구요...

혹시 다른차이가 있나요?

 

def route(self, rule: str, **options: t.Any) -> t.Callable:
"""Decorate a view function to register it with the given URL
rule and options. Calls :meth:`add_url_rule`, which has more
details about the implementation.

:param rule: The URL rule string.
:param options: Extra options passed to the
:class:`~werkzeug.routing.Rule` object.
"""

def decorator(f: t.Callable) -> t.Callable:
endpoint = options.pop("endpoint", None)
self.add_url_rule(rule, endpoint, f, **options)
return f

return decorator

 

데코레이터python플라스크rest-apiflask

Answer 1

0

funcoding님의 프로필 이미지
funcoding
Instructor

안녕하세요.

음 저 코드를 처음 봐서, 어떤 코드인지를 몰라서, 정확히 설명을 드리기는 어려워보이네요. 영상에서 설명드린 데코레이터 사용방법과는 달라보입니다. 데코레이터를 호출하는 코드라기 보다, 뭔가 데코레이터를 구현하는 코드로 보여서, 데코레이터 사용 문법과는 관련이 없어보입니다.

감사합니다.

immutable000's profile image
immutable000

asked

Ask a question