Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#15730 closed New feature (fixed)

RequestFactory Example Doesn't Address Class-Based Views

Reported by: Bryan Veloso Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Was attempting to use RequestFactory with class-based generic views. The example as it stands is for functional views only.

Attachments (2)

requestfactory-with-cbvs.patch (939 bytes ) - added by Bryan Veloso 14 years ago.
15730.diff (2.1 KB ) - added by Tim Graham 12 years ago.
Add doc method for View.as_view

Download all attachments as: .zip

Change History (13)

by Bryan Veloso, 14 years ago

comment:1 by Luke Plant, 14 years ago

Severity: Normal
Type: Uncategorized

To my mind, the example is sufficient, because class-based views are not special, and don't need any special docs. They have no special handling internally to Django. A view is a callable that takes a request and returns a response. The .as_view() method of CBVs simply returns a callable which is such a view. In fact, in the example given, there is nothing to say that my_view is a function, and not any other callable, even one derived from a CBV.

However, I'm aware that lots of people may not get this. But I'm still kind of reluctant to go through every example of a view being used and give CBV based example when there is no need to, since they work identically. Perhaps we need to explain this aspect of CBVs more clearly.

comment:2 by Bryan Veloso, 14 years ago

Thanks for taking a look Luke. I agree with you 100%. While I was doing the patch, I was like... "It probably would be just as good to throw the fact that you can pass a request like that in the conversion documents (http://docs.djangoproject.com/en/1.3/topics/generic-views-migration/)." As long as there's some eduction about this (as I would have never figured out that View.as_view()(request) was the correct way to go about it), I'll be happy. :)

comment:3 by Luke Plant, 14 years ago

Type: UncategorizedNew feature

comment:4 by Gabriel Hurley, 14 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Mentioning this in a generic fashion sounds good to me (as per Luke).

comment:5 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:11 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 by travisby@…, 12 years ago

As a new user, I would like to admit that I would have NEVER figured that out. I've been looking for two days, and finally saw that you're suppose dto use GenericViewClass.as_view()(request)

The worst part is, I still don't understand what it does (but hey, it works). I think it would be very beneficial to add to the documentation.

by Tim Graham, 12 years ago

Attachment: 15730.diff added

Add doc method for View.as_view

comment:14 by Tim Graham, 12 years ago

Cc: timograham@… added
Patch needs improvement: unset

comment:15 by Tim Graham <timograham@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [b139cfc0f7e70e37b9a31e9931c6b03b8a68e918]:

Fixed #15730 - Documented the as_view() method for CBVs.

comment:16 by raymond@…, 11 years ago

Although more verbose, the format of

generic_view = GenericViewClass.as_view()
generic_view(request)

makes it a bit easier to see what's happening

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