-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Clarify APIView.dispatch request lifecycle in docstring #9884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ source: | |
| > | ||
| > — [Reinout van Rees][cite] | ||
|
|
||
| REST framework provides an `APIView` class, which subclasses Django's `View` class. | ||
| REST framework provides an `APIView` class, which subclasses Django’s base `View` class. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "inherits" ? |
||
|
|
||
|
|
||
| `APIView` classes are different from regular `View` classes in the following ways: | ||
|
|
||
|
|
@@ -19,7 +20,9 @@ REST framework provides an `APIView` class, which subclasses Django's `View` cla | |
| * Any `APIException` exceptions will be caught and mediated into appropriate responses. | ||
| * Incoming requests will be authenticated and appropriate permission and/or throttle checks will be run before dispatching the request to the handler method. | ||
|
|
||
| Using the `APIView` class is pretty much the same as using a regular `View` class, as usual, the incoming request is dispatched to an appropriate handler method such as `.get()` or `.post()`. Additionally, a number of attributes may be set on the class that control various aspects of the API policy. | ||
| Using the `APIView` class is very similar to using a regular Django `View` class. | ||
| As usual, the incoming request is dispatched to an appropriate handler method such as `.get()` or `.post()`. | ||
|
|
||
|
|
||
| For example: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -490,9 +490,22 @@ def raise_uncaught_exception(self, exc): | |
| # be overridden. | ||
| def dispatch(self, request, *args, **kwargs): | ||
| """ | ||
| `.dispatch()` is pretty much the same as Django's regular dispatch, | ||
| but with extra hooks for startup, finalize, and exception handling. | ||
| Dispatch the incoming request to the appropriate handler method. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good, mentioning the flow is actually a good point
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's definitely an improvement |
||
|
|
||
| This method implements the core request/response lifecycle for | ||
| Django REST Framework views: | ||
|
|
||
| 1. Wraps the incoming Django HttpRequest in a REST framework Request. | ||
| 2. Performs content negotiation, authentication, permission, and | ||
| throttling checks. | ||
| 3. Resolves and calls the appropriate HTTP method handler | ||
| (e.g. get(), post(), put()). | ||
| 4. Handles any exceptions raised during processing and converts | ||
| them into appropriate Response objects. | ||
| 5. Finalizes and returns the response with proper rendering | ||
| and headers applied. | ||
| """ | ||
|
|
||
| self.args = args | ||
| self.kwargs = kwargs | ||
| request = self.initialize_request(request, *args, **kwargs) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in this file were rejected in #9882 please don't submit them again