Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#26660 closed Uncategorized (wontfix)

Remove ugly .as_view() requeriment

Reported by: john-bonachon Owned by: nobody
Component: Core (URLs) Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Let's take this urls.py as an example,

from django.conf.urls import url

from . import views

app_name = 'polls'

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]

Is there any elegant "trick" to avoid calling the method .as_view() and make the Class View callable? I'm not sure if using __call__ magic function on django.views.generic.View would help on this.

It may have sense to make the developer remember that you must send a callable that will receive an HttpRequest plus the regex arguments, however url() is also accepting a list or tuple for include() processing, so I wonder if we could also just send the Class View.

Change History (2)

comment:1 Changed 3 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

The .as_view() requirement exists for a reason; if you'd like to see a summary of the design process, you can see the options considered here: https://code.djangoproject.com/wiki/ClassBasedViews

comment:2 Changed 3 years ago by john-bonachon

Thanks, and please remove this ticket if necessary.
My bad.

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