Types of Views in Django
1. Function-Based Views (FBVs):
from django.http import HttpResponse
def my_view(request):
return HttpResponse("Hello, Django!") 2. Class-Based Views (CBVs):
from django.http import HttpResponse
from django.views import View
class MyView(View):
def get(self, request):
return HttpResponse("Hello, Django!") 3. Generic Class-Based Views:
4. Template Views:
5. Class-Based Views with Mixins:
Important Note
These are just a few examples, and Django provides flexibility for creating custom views based on your application's needs. The choice of which type of view to use depends on the complexity and requirements of your project.
Last updated