2 ms·
When using class-based views, this is already built in. You can do something this: from django.views.generic.base import View from django.http import H
by crgwbr 14y ago
When using class-based views, this is already built in. You can do something this:
from django.views.generic.base import View
from django.http import HttpResponse
class MyView(View):
def get(self, request):
return HttpResponse("Get request")
def post(self, request):
return HttpResponse("Post Request")
The functionality to make this "just work" (dispatch based on method) is built into django.views.generic.base.View.dispatch.