Hello I would like to ask why the class based views documentation seems so much ugly. Some developers probably are scared by these just because the decoration is ugly, the documentation offers three ways:
Decorate the
Klass().dispach() method of the class, wrapping the decorators in another decorator:
@method_decorator(decorator_1)
def dispatch(request, *args, **kwargs):
pass
Wrapping the
Klass.as_view() resulting in an arguably ugly
:
decorator_1( decorator_2( .. ( .. decorator_n( Klass.as_view() ) .. ) .. ))
In my opinion this is an issue
because decoration is actually cool
and
the alternative is to use the much more dreadful Multiple Inheritance, that is the documented third way.
I personally use reduce syntax:
view = reduce(lambda x, f: f(x), (decorator_1, decorator_2, .., decorator_n), Klass.as_view())
Probably there are better ways but still to me it seems to me that something like this is more readable, easier to modify and less scary. To me it has the pro that one could easily wrap common used decorators in a single iterable.