Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rest_framework/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def api_view(http_method_names=None):
Decorator that converts a function-based view into an APIView subclass.
Takes a list of allowed methods for the view as an argument.
"""
if http_method_names is None:
http_method_names = ['GET']
http_method_names = ['GET'] if http_method_names is None else http_method_names

def decorator(func):

Expand Down Expand Up @@ -109,10 +108,12 @@ def decorator(func):
return decorator


def detail_route(methods=['get'], **kwargs):
def detail_route(methods=None, **kwargs):
"""
Used to mark a method on a ViewSet that should be routed for detail requests.
"""
methods = ['get'] if methods is None else methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor one, this, but I tend to prefer using brackets around the if clause for visual clarity, so I normally do...

['get'] if (methods is None) else methods


def decorator(func):
func.bind_to_methods = methods
func.detail = True
Expand All @@ -121,10 +122,12 @@ def decorator(func):
return decorator


def list_route(methods=['get'], **kwargs):
def list_route(methods=None, **kwargs):
"""
Used to mark a method on a ViewSet that should be routed for list requests.
"""
methods = ['get'] if methods is None else methods

def decorator(func):
func.bind_to_methods = methods
func.detail = False
Expand Down