CBV : Class-based views
Class가 기반이 되는 views
from django.http import HttpResponse from django.views import View class GreetingView(View): greeting = "Good Day" def get(self, request): return HttpResponse(self.greeting)
FBV : Function-based views
- Funtion이 기반이 되는 views. 간단한 task에 사용
def userRegist(request): if request.method == "POST": return HttpResponse("POST method 입니다.") else: return HttpResponse(request.method, "method 입니다.")
django의 CBV Document에 보면
The problem with function-based generic views is that while they covered the simple cases well, there was no way to extend or customize them beyond some configuration options, limiting their usefulness in many real-world applications.
라고 나와있습니다. FBV의 문제는 simple case에서는 잘 동작하나, 상속, customize 부분에서는 약하며 이는 비효율적이라고 나와있습니다.
CBV와 FBV를 써야하는 부분이 어딘지는 아직 정확히 모르겠지만, 일반적인 상황에서는 FBV를 사용해도 상관 없으나, 상속 등의 문제로 인해 클래스의 기능이 필요하다면 CBV를 사용해야 합니다.
'개발공부 > django' 카테고리의 다른 글
django와 postgresql 연동 (0) | 2020.04.20 |
---|---|
Django - 1 (0) | 2019.09.30 |