Code

Opened 4 years ago

Closed 3 years ago

#13635 closed New feature (fixed)

URLconfs should accept classes as views

Reported by: bfirsh Owned by: bfirsh
Component: Core (Other) Version: master
Severity: Normal Keywords: urlconf
Cc: bfirsh 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 bfirsh 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 follow-up: Changed 4 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 4 years ago by bfirsh

  • Has patch set
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 4 years ago by apollo13

  • Triage Stage changed from Ready for checkin to Unreviewed

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

comment:4 Changed 4 years ago by bfirsh

  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by bfirsh

comment:5 Changed 4 years ago by bfirsh

New patch with clearer tests.

comment:6 in reply to: ↑ 1 Changed 4 years ago by bfirsh

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 4 years ago by bfirsh

  • Triage Stage changed from Accepted to Design decision needed

comment:8 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 3 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 3 years ago by russellm

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

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.