Grokking Django
Vote

0% completed

​

Function-Based Views (FBVs) vs Class-Based Views (CBVs)

Here is the contact page of the blog, written twice. Both versions answer GET and POST requests with the same text, but they give different answers to a PUT request, and the difference shows how the two styles of view work.

# blog/views.py from django.http import HttpResponse def contact_view(request): if request.method == "GET": return HttpResponse("This is the contact form.") elif request.method == "POST": return HttpResponse("Form submitted successfully!")
# blog/views.py from django.http import HttpResponse from django

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content