Opened 15 years ago
Closed 14 years ago
#13635 closed New feature (fixed)
URLconfs should accept classes as views
Reported by: | Ben Firshman | Owned by: | Ben Firshman |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | urlconf |
Cc: | Ben Firshman | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If a URLconf is passed a class, and isinstance(cls, type) is true, it should instantiate the class on each request and call it. This makes class based views (#6735) trivially thread safe.
Attachments (1)
Change History (11)
follow-up: 6 comment:1 by , 15 years ago
comment:2 by , 14 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
comment:3 by , 14 years ago
Triage Stage: | Ready for checkin → Unreviewed |
---|
Plz don't change triage stages; this is not ready for checkin
comment:4 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 14 years ago
Attachment: | 13635.diff added |
---|
comment:6 by , 14 years ago
Replying to lukeplant:
Personally, I think that we should instead encourage people to create view functions out of view classes:
my_view = make_view(MyViewClass)(where
make_view
is a very easy to write utility that would be included in core). This makes it much easier to handle decorators, and insulates the URLconf from implementation details (like the fact that the view is implemented using a class).
We had some discussion about this: http://groups.google.com/group/django-developers/browse_thread/thread/e23d9a5a58fe5891/23b9b3aa96bbb7f2?lnk=gst
But not many people responded to my point of view.
I like this method because it is transparent for people who don't understand the threading issues. It would be quite confusing for users to explain why they need to use make_view().
comment:7 by , 14 years ago
Triage Stage: | Accepted → Design decision needed |
---|
This may not be necessary. More discussion:
comment:8 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:9 by , 14 years ago
Easy pickings: | unset |
---|
Is this still necessary, given that we can do it this way: http://docs.djangoproject.com/en/dev/ref/class-based-views/#generic-views
comment:10 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Agreed - this was resolved with the introduction of generic views.
Personally, I think that we should instead encourage people to create view functions out of view classes:
(where
make_view
is a very easy to write utility that would be included in core). This makes it much easier to handle decorators, and insulates the URLconf from implementation details (like the fact that the view is implemented using a class).We had some discussion about this: http://groups.google.com/group/django-developers/browse_thread/thread/e23d9a5a58fe5891/23b9b3aa96bbb7f2?lnk=gst
But not many people responded to my point of view.