#27289 closed Bug (fixed)
Docs: Badly wrong explanation of View.as_view() and its use in urlconf
Reported by: | Graham Wideman | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | CBV as_view |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In the Introduction to class-based view (for example, https://docs.djangoproject.com/en/1.10/topics/class-based-views/intro/) the explanation for the as_view() method is wrong in a way which undermines clear understanding of a crucial piece of the CBV apparatus.
Existing narrative: "Because Django’s URL resolver expects to send the request and associated arguments to a callable function, not a class, class-based views have an as_view() class method which serves as the callable entry point to your class. The as_view entry point creates an instance of your class and calls its dispatch() method."
The as_view() class method is NOT the entry point and does NOT instantiate your class. If as_view() were the entry point, then its use in urlpatterns would omit the function brackets, and the subsequent Note about setting class attributes would make no sense.
The narrative should be changed to something more like:
"Django’s URL resolver expects to send the request and associated arguments to a callable function (as it does for function-based views), and so will not accept a class as the view argument in the url() function. Consequently, the View base class provides the as_view() class method which *returns a class method* that serves as the callable entry point to your class. Note that the as_view() function itself is *not* the entry point per se. The function that as_view() returns (called later by the URL resolver when a request arrives for a URL matching the associated pattern) is responsible for instantiating your actual view class, and calling its dispatch() method."
Change History (5)
follow-up: 2 comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 8 years ago
Replying to Tim Graham:
Care to submit a pull request?
I am not really in a position any time soon to divert to figuring out what all I'd need to fork to make this change and have it end up as an appropriate patch. Also I wouldn't know how to get this change to apply to all the generations of docs it applies to. So, I'm afraid if you wait for me this probably won't get done. Sorry :-(
Care to submit a pull request?