Introduction
Creating views is a crucial aspect of Django development, allowing you to handle user requests, process data, and generate responses. This documentation focuses on a function-based view that provides information about the application through the About page.
Function-Based Views
from django.http import HttpResponse
def about(request): """
View providing information about the application.
"""
return HttpResponse("This is the About Page.")
Class-Based Views
While function-based views are simple and effective, Django also supports class-based views (CBVs) for more structured and reusable code. Class-based views provide a way to organize views into classes, offering additional functionality.
from django.views import View
from django.http import HttpResponse
class GreetingView(View):
"""
Example of a class-based view.
"""def get(self, request):
"""
Handles GET requests.
"""
return HttpResponse("Hello, this is a class-based view!")