Function-Based View:
Function-based views are the traditional way of writing views in Django. It is a function that takes a web request and returns a web response. It is a simple and straightforward way of creating views.

Example:
def hello_world(request):
return HttpResponse(“Hello World!”)

Class-Based View:
Class-based views are an alternative way of writing views in Django. It is a class that inherits from a View class. It is more object-oriented and provides more features and flexibility.

Example:
class HelloWorldView(View):
def get(self, request):
return HttpResponse(“Hello World!”)

Leave a Reply

Your email address will not be published. Required fields are marked *