Class Based Views
A class based view organises code by HTTP method. Use as_view() in urls.py.
Example
from django.views import View
class HelloView(View):
def get(self, request):
return HttpResponse("GET hello")
def post(self, request):
return HttpResponse("POST hello")
path("hello/", HelloView.as_view())Exercise
Use a class view in urls.
HelloView.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.