white-magazine-23424
10/29/2021, 9:42 PMtemplate_name as a kwarg to the Response constructor, drf passes data (first argument to the constructor) as context to the template behind the scenes if the request if for the content type of text/html
So:
python
@api_view
def foo_view(request):
return Response({'message': 'hello!'}, template_name="foo.html")
html
<h1>{{ messgae }}</h1>