7 Days Challenge to Push Your Hard Skill Using Django part 3: Which CBV or FBV should be used?
hello and welcome to another blog post, in this post I will talk about Which CBVor FBV should be used, in the previews part we will restructure the Django project with a modular structure, now in Now on the third day we will discuss how to determine our project views using FBV or CBV, now, here is a diagram

the recommended use Function-Based View for a complicated logic/view or custom error handling and use CBV for most views for example simple crud operation or many others
Better Way to Create Url Conf
these are some tips on how to practically select and use URLs in Django
Keep View Logic Out from urls.py
now we let a look at an example taste/views.py
from django.urls import reverse
from django.views.generic import ListView, DetailView, UpdateView
from .models import Tastingclass TasteListView(ListView):
model = Tastingclass TasteDetailView(DetailView):
model = Tastingclass TasteResultsView(TasteDetailView):
template_name = 'tastings/results.html'class TasteUpdateView(UpdateView):
model = Tasting
the better urls.py
we can create like this
from django.urls import path
from . import viewsurlpatterns = [path(route='',view=views.TasteListView.as_view(), name='list'),path(route='<int:pk>/', view=views.TasteDetailView.as_view(), name='detail'),
path(route='<int:pk>/results/',view=views.TasteResultsView.as_view(), name='results'), path(route='<int:pk>/update/',view=views.TasteUpdateView.as_view(),name='update')]
the wrong example is an include logic at urls.py
like this
urlpatterns = [path('<int:pk>',DetailView.as_view(model=Tasting,template_name='tastings/detail.html'),name='detail'),path('<int:pk>/results/',DetailView.as_view(model=Tasting,template_name='tastings/results.html'),name='results'),
]
Conclusion
So the conclusion that we will get after understanding is that we choose to use the base view class or the base view function is based on the case we are going to work on, and the complexity of the view features that we create.