Add "view_decorators" to django.views.generic.View

118 views
Skip to first unread message

Curtis

unread,
Dec 21, 2015, 8:49:24 AM12/21/15
to django-d...@googlegroups.com
Hey all,

Tim wanted me to open some discussion on this idea:

https://github.com/django/django/pull/5637/files

Essentially, it allows you to add an explicit list of decorators for a
View to apply to its view function when someone calls as_view.

This allows the View author to dictate which decorators are needed,
instead of relying on whomever includes it in their URL pattern to
remember it.

--
Curtis

Carl Johnson

unread,
Dec 21, 2015, 12:03:15 PM12/21/15
to Django developers (Contributions to Django itself)
I would find that useful. In my experience, I often have a mixture of CBV and non-CBV code, and it's annoying to shoehorn decorators into the as_view method. It would be much more convenient to just add to self.view_decorators.

Tim Graham

unread,
Dec 21, 2015, 12:19:58 PM12/21/15
to Django developers (Contributions to Django itself)
Could you summarize the pros and cons of this new technique versus the existing @method_decorator() recommendation [1]? Does it duplicate all the functionality provided by method_decorator such that we would no longer recommend that technique in the class-based view docs?

[1] https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class

Marc Tamlyn

unread,
Dec 22, 2015, 12:36:15 PM12/22/15
to django-d...@googlegroups.com
Personally, I find that decorators aren't the best way of interacting with CBVs. They're useful when you have a mixed style codebase, but I tend to convert the decorator into a mixin applied at the appropriate point. I think the style of decorating in the URLconf is horrible.

Marc

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/39d40372-9e63-4dfc-9378-b2187a95bd25%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages