Opened 7 years ago

Closed 6 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: master
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:

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 7 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by Luke Plant

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 Changed 7 years ago by Ben Firshman

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:3 Changed 7 years ago by Florian Apolloner

Triage Stage: Ready for checkinUnreviewed

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

comment:4 Changed 7 years ago by Ben Firshman

Triage Stage: UnreviewedAccepted

Changed 7 years ago by Ben Firshman

Attachment: 13635.diff added

comment:5 Changed 7 years ago by Ben Firshman

New patch with clearer tests.

comment:6 in reply to:  1 Changed 7 years ago by Ben Firshman

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 Changed 7 years ago by Ben Firshman

Triage Stage: AcceptedDesign decision needed

comment:8 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:9 Changed 6 years ago by Graham King

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 Changed 6 years ago by Russell Keith-Magee

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