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 HttpResponse for quick plain text or HTML.
  • Set content_type explicitly when returning non-HTML.
  • Category Views (FBV & CBV)
  • Total Views 1373
  • Last Modified 16 November, 2025
  • Tags #fbv #httpresponse #views #basics
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.