Opened 5 years ago

Closed 4 years ago

Last modified 2 years ago

#15730 closed New feature (fixed)

RequestFactory Example Doesn't Address Class-Based Views

Reported by: bryanveloso 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


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 bryanveloso 5 years ago.
15730.diff (2.1 KB) - added by timo 4 years ago.
Add doc method for View.as_view

Download all attachments as: .zip

Change History (13)

Changed 5 years ago by bryanveloso

comment:1 Changed 5 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Severity set to Normal
  • Type set to 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 bryanveloso

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 (" 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 lukeplant

  • Type changed from Uncategorized to New feature

comment:4 Changed 5 years ago by gabrielhurley

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:5 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:11 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:12 Changed 4 years ago by aaugustin

  • 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 timo

Add doc method for View.as_view

comment:14 Changed 4 years ago by timo

  • Cc timograham@… added
  • Patch needs improvement unset

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

  • Resolution set to fixed
  • Status changed from new to closed

In [b139cfc0f7e70e37b9a31e9931c6b03b8a68e918]:

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

comment:16 Changed 2 years ago by raymond@…

Although more verbose, the format of

generic_view = GenericViewClass.as_view()

makes it a bit easier to see what's happening

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