Opened 14 years ago
Closed 11 years ago
#15303 closed Cleanup/optimization (needsinfo)
Clarify View.as_view() docs in respect to functions passed as kwargs.
Reported by: | Gabriel Grant | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Problem:
At the moment, generic.base.View.as_view() passes kwargs to the class' init (which setattr
s them), rather than dynamically subclassing. The introductory generic view docs, however, seem to imply that passing kwargs to the as_view() method is equivalent to overriding the class. For example, it refers to "pass[ing] the new attributes into the as_view method call" as an "overriding pattern." This makes it rather surprising that functions passed to as_view() aren't bound to the resultant instance.
Possible Resolutions:
It seems to me that as_view() should dynamically create a subclass with the provided kwargs. Alternatively, if that is deemed undesirable, the docs should at least be clarified to better explain the true behaviour.
I can provide a patch, but need someone (*cough* RKM :) to confirm the desired behaviour.
Change History (8)
comment:1 by , 14 years ago
Component: | Generic views → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Summary: | Functions passed as kwargs to View.as_view() should be bound → Clarify View.as_view() docs in respect to functions passed as kwargs. |
Type: | → Cleanup/optimization |
comment:13 by , 12 years ago
Has patch: | set |
---|
Not sure if this patch was in response to this ticket, but this looks related at least: https://github.com/django/django/pull/314
comment:14 by , 12 years ago
Has patch: | unset |
---|
I've merged the pull request above, but it seems like there may be additional clarification that should be added (not sure what exactly).
comment:15 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
@gg, if you can provide a patch please reopen. Otherwise, I'm not sure what further clarification (if any) is needed here.
As discussed on IRC: I'm not sure I see why we should make the implementation of the generic view base class a whole lot more complicated in order to allow users to avoid creating a subclass. Passing arguments in to as_view() is a convenience for the really simple cases -- it isn't intended as a way to avoid ever needed to create a View subclass.
However, I can see how the phrasing about "overriding pattern" could lead to this expectation, so that should be cleaned up.