Basic Function-Based View with HttpResponse
A minimal FBV that returns an HttpResponse with plain text.
# views.py
from django.http import HttpResponse
def ping(request):
print("ping request received")
print(request.headers)
return HttpResponse("pong", content_type="text/plain")
# urls.py
path("ping/", ping, name="ping")
Explanation:
-
Use
HttpResponsefor quick plain text or HTML. -
Set
content_typeexplicitly when returning non-HTML.
- Category Views (FBV & CBV)
- Total Views 1373
- Last Modified 16 November, 2025
- Tags #fbv #httpresponse #views #basics
Previous snippet
Multi-Step Form Wizard
Next snippet