1.

What are views in Django?

Answer»

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 HttpResponsedef 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.


Discussion

No Comment Found