Opened 5 years ago

Closed 4 years ago

Last modified 3 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 5 years ago.
15730.diff (2.1 KB) - added by Tim Graham 4 years ago.
Add doc method for View.as_view

Download all attachments as: .zip

Change History (13)

Changed 5 years ago by Bryan Veloso

comment:1 Changed 5 years ago by Luke Plant

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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 Changed 5 years ago by Bryan Veloso

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 Changed 5 years ago by Luke Plant

Type: UncategorizedNew feature

comment:4 Changed 5 years ago by Gabriel Hurley

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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

comment:5 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:11 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 Changed 4 years ago by travisby@…

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.

Changed 4 years ago by Tim Graham

Attachment: 15730.diff added

Add doc method for View.as_view

comment:14 Changed 4 years ago by Tim Graham

Cc: timograham@… added
Patch needs improvement: unset

comment:15 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In [b139cfc0f7e70e37b9a31e9931c6b03b8a68e918]:

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

comment:16 Changed 3 years ago by raymond@…

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