Complete the code to define a function-based view that returns a simple HTTP response.
from django.http import HttpResponse def my_view(request): return [1]("Hello, world!")
The function-based view returns an HttpResponse object with the text.
Complete the code to import the base class for class-based views.
from django.views import [1]
The base class for all class-based views is View from django.views.
Fix the error in the class-based view by completing the method name that handles GET requests.
from django.views import View from django.http import HttpResponse class MyView(View): def [1](self, request): return HttpResponse("Hello from class-based view")
The method to handle GET requests in a class-based view is named get.
Fill both blanks to complete a function-based view that renders a template with context.
from django.shortcuts import [1] def home(request): context = {'name': 'Alice'} return [2](request, 'home.html', context)
The render shortcut both imports and returns a rendered template with context.
Fill all three blanks to complete a class-based view that renders a template with extra context.
from django.views.generic import [1] class WelcomeView([2]): template_name = 'welcome.html' def get_context_data(self, **kwargs): context = super().[3](**kwargs) context['user'] = 'Bob' return context
TemplateView is used to render templates in class-based views. The method get_context_data adds extra data to the template context.