Today’s Offer Enroll today and get access to premium content.
App Store Google Play
Intermediate

What are Django views and how do they differ from templates?

In Django, views are Python functions or classes that handle the business logic of your application, while templates are HTML files used to present data to the user.

To create a view, follow these steps:

  1. Define a function in views.py.
  2. Use render() to return a template.
  3. Map the view to a URL in urls.py.

Example of a view:

from django.shortcuts import render

def home(request):
    return render(request, 'home.html')