From 051bee14bf3d760ca3ea152f093addc88526d8cf Mon Sep 17 00:00:00 2001 From: Rustem Muslimov Date: Sat, 20 Aug 2016 14:30:45 +0300 Subject: [PATCH] Allow api_view setup attrs mentioned explicitly --- rest_framework/decorators.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 1b21e643b..69a8b6ebc 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -15,7 +15,7 @@ from django.utils import six from rest_framework.views import APIView -def api_view(http_method_names=None): +def api_view(http_method_names=None, **kwargs): """ Decorator that converts a function-based view into an APIView subclass. Takes a list of allowed methods for the view as an argument. @@ -71,6 +71,10 @@ def api_view(http_method_names=None): WrappedAPIView.permission_classes = getattr(func, 'permission_classes', APIView.permission_classes) + # Extend APIView with attrs mentioned explicitly + for (attrname, attrvalue) in kwargs.items(): + setattr(WrappedAPIView, attrname, attrvalue) + return WrappedAPIView.as_view() return decorator