Opened 13 years ago

Closed 10 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 setattrs 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 Russell Keith-Magee, 13 years ago

Component: Generic viewsDocumentation
Triage Stage: UnreviewedAccepted

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.

comment:2 by Łukasz Rekucki, 13 years ago

Severity: Normal
Summary: Functions passed as kwargs to View.as_view() should be boundClarify View.as_view() docs in respect to functions passed as kwargs.
Type: Cleanup/optimization

comment:3 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:11 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 by Tim Graham, 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 Tim Graham, 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 Tim Graham, 10 years ago

Resolution: needsinfo
Status: newclosed

@gg, if you can provide a patch please reopen. Otherwise, I'm not sure what further clarification (if any) is needed here.

Note: See TracTickets for help on using tickets.
Back to Top