`.dispatch()` is pretty much the same as Django's regular dispatch, but with extra hooks for startup, finalize, and exception handling.
(self, request, *args, **kwargs)
| 489 | # accidental removal of this exemption in cases where `dispatch` needs to |
| 490 | # be overridden. |
| 491 | def dispatch(self, request, *args, **kwargs): |
| 492 | """ |
| 493 | `.dispatch()` is pretty much the same as Django's regular dispatch, |
| 494 | but with extra hooks for startup, finalize, and exception handling. |
| 495 | """ |
| 496 | self.args = args |
| 497 | self.kwargs = kwargs |
| 498 | request = self.initialize_request(request, *args, **kwargs) |
| 499 | self.request = request |
| 500 | self.headers = self.default_response_headers # deprecate? |
| 501 | |
| 502 | try: |
| 503 | self.initial(request, *args, **kwargs) |
| 504 | |
| 505 | # Get the appropriate handler method |
| 506 | if request.method.lower() in self.http_method_names: |
| 507 | handler = getattr(self, request.method.lower(), |
| 508 | self.http_method_not_allowed) |
| 509 | else: |
| 510 | handler = self.http_method_not_allowed |
| 511 | |
| 512 | response = handler(request, *args, **kwargs) |
| 513 | |
| 514 | except Exception as exc: |
| 515 | response = self.handle_exception(exc) |
| 516 | |
| 517 | self.response = self.finalize_response(request, response, *args, **kwargs) |
| 518 | return self.response |
| 519 | |
| 520 | def options(self, request, *args, **kwargs): |
| 521 | """ |
no test coverage detected