오픈소스/Django
Django의 classonlymethod 알아보기
bluebamus
2021. 6. 20. 14:45
classonlymethod 데코레이터의 역할이 궁금해서 찾아봄
결론적으로 말하자면, 해당 함수의 인스턴스가 None이 아닌경우 에러를 출력한다.
에러 메시지로는 이 메소드는 오직 뷰 클래스에서만 사용할 수 있다
classonlymethod는 클래스에서만 호출할 수 있다
소스코드
class classonlymethod(classmethod):
def __get__(self, instance, owner):
if instance is not None:
raise AttributeError("This method is available only on the view class.")
return super(classonlymethod, self).__get__(instance, owner)