diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 415105c76..c9b2695f6 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -148,13 +148,7 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs): func.bind_to_methods = methods func.detail = detail func.url_path = url_path if url_path else func.__name__ - func.url_name = url_name - if not url_name: - # Remove in 3.10 - if kwargs.get('_url_name_from_path', False): - func.url_name = func.url_path.replace('_', '-') - else: - func.url_name = func.__name__.replace('_', '-') + func.url_name = url_name if url_name else func.__name__.replace('_', '-') func.kwargs = kwargs return func return decorator @@ -169,7 +163,13 @@ def detail_route(methods=None, **kwargs): "`action`, which accepts a `detail` bool. Use `@action(detail=True)` instead.", PendingDeprecationWarning, stacklevel=2 ) - return action(methods, detail=True, _url_name_from_path=True, **kwargs) + + def decorator(func): + func = action(methods, detail=True, **kwargs)(func) + if 'url_name' not in kwargs: + func.url_name = func.url_path.replace('_', '-') + return func + return decorator def list_route(methods=None, **kwargs): @@ -181,4 +181,10 @@ def list_route(methods=None, **kwargs): "`action`, which accepts a `detail` bool. Use `@action(detail=False)` instead.", PendingDeprecationWarning, stacklevel=2 ) - return action(methods, detail=False, _url_name_from_path=True, **kwargs) + + def decorator(func): + func = action(methods, detail=False, **kwargs)(func) + if 'url_name' not in kwargs: + func.url_name = func.url_path.replace('_', '-') + return func + return decorator