python-requests Django Framework Core Concepts - Views


A view is any piece of code that responds to a request and returns a response. Views normally return templates along with a dictionary (called the context) which usually contains data for placeholders in the template. In django projects, views are located in the module of applications.

The simplest view, returns a direct response:

from django.http import HttpResponse

def simple_view(request):
   return HttpResponse('<strong>Hello World</strong>')

However, most views utilize a template:

from django.shortcuts import render

def simple_template_view(request):
    return render(request, 'some_template.html')

A template is simply any file, and it can optionally contain special markup for added functionality; what this means is that django views can return any kind of response, not just HTML.