Opened 14 years ago

Closed 13 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)

13635.diff (6.5 KB ) - added by Ben Firshman 14 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Luke Plant, 14 years ago

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.

comment:2 by Ben Firshman, 14 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:3 by Florian Apolloner, 14 years ago

Triage Stage: Ready for checkinUnreviewed

Plz don't change triage stages; this is not ready for checkin

comment:4 by Ben Firshman, 14 years ago

Triage Stage: UnreviewedAccepted

by Ben Firshman, 14 years ago

Attachment: 13635.diff added

comment:5 by Ben Firshman, 14 years ago

New patch with clearer tests.

in reply to:  1 comment:6 by Ben Firshman, 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 Ben Firshman, 14 years ago

Triage Stage: AcceptedDesign decision needed

comment:8 by Julien Phalip, 14 years ago

Severity: Normal
Type: New feature

comment:9 by Graham King, 13 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 Russell Keith-Magee, 13 years ago

Resolution: fixed
Status: newclosed

Agreed - this was resolved with the introduction of generic views.

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