Complete the code to import the Django HttpResponse class.
from django.http import [1]
The HttpResponse class is used to send a response back to the client in Django.
Complete the code to define a Django view function that takes a request parameter.
def my_view([1]): return HttpResponse('Hello World')
The first parameter of a Django view function is usually request, representing the incoming HTTP request.
Fix the error in the code to return a plain text response with status code 404.
from django.http import HttpResponse def not_found_view(request): return HttpResponse('Page not found', [1]=404)
The correct keyword argument to set the HTTP status code in HttpResponse is status_code.
Fill both blanks to access a GET parameter named 'name' from the request.
def greet_view(request): name = request.[1].get('[2]', 'Guest') return HttpResponse(f'Hello, {name}!')
GET parameters are accessed via request.GET. The parameter name here is 'name'.
Fill all three blanks to create a JSON response with a dictionary containing a message.
from django.http import JsonResponse def json_view(request): data = [1](message='Hello') return [2](data, safe=[3])
We create a dictionary with dict, then return it with JsonResponse. The safe parameter must be True when passing a dictionary.