Google News
logo
Django - Interview Questions
What are views in Django?
A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response. This response can be HTML contents of a web page, or a redirect, or a 404 error, or an XML document, or an image, etc. 
 
Example :
from django.http import HttpResponse
def sample_function(request):
 return HttpResponse(“Welcome to Django”)

 

There are two types of views :
 
Function-Based Views : In this, we import our view as a function.
Class-based Views : It’s an object-oriented approach.
Advertisement