#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)
Change History (13)
by , 14 years ago
Attachment: | requestfactory-with-cbvs.patch added |
---|
comment:1 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Uncategorized |
comment:2 by , 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 , 14 years ago
Type: | Uncategorized → New feature |
---|
comment:4 by , 14 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Mentioning this in a generic fashion sounds good to me (as per Luke).
comment:13 by , 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.
comment:14 by , 12 years ago
Cc: | added |
---|---|
Patch needs improvement: | unset |
comment:15 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:16 by , 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
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 thatmy_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.