According to View's dispatch method that you can find here:-
https://ccbv.co.uk/projects/Django/2.0/django.views.generic.base/View/
def dispatch(self, request, *args, **kwargs):
# Try to dispatch to the right method; if a method doesn't exist,
# defer to the error handler. Also defer to the error handler if the
# request method isn't on the approved list.
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed
return handler(request, *args, **kwargs)
If you don't define get method in View, then dispatch will call self.http_method_not_allowed
def http_method_not_allowed(self, request, *args, **kwargs):
logger.warning(
'Method Not Allowed (%s): %s', request.method, request.path,
extra={'status_code': 405, 'request': request}
)
return HttpResponseNotAllowed(self._allowed_methods())
Here,
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
In this piece of code the if condition will pass ,but when it will try to do getattr on self, request.method.lower() have get as value, so getattr will not find get method , because we have not defined it, so getattr will return http_method_not_allowed