Skip to content

Commit 0b7c346

Browse files
author
Ryan P Kilby
committed
Allow view name/desc to be set by view initkwargs
1 parent 4890208 commit 0b7c346

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

rest_framework/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def get_view_name(view):
3030
3131
This function is the default for the `VIEW_NAME_FUNCTION` setting.
3232
"""
33+
if view.name is not None:
34+
return view.name
35+
3336
name = view.__class__.__name__
3437
name = formatting.remove_trailing_string(name, 'View')
3538
name = formatting.remove_trailing_string(name, 'ViewSet')
@@ -50,7 +53,11 @@ def get_view_description(view, html=False):
5053
5154
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
5255
"""
53-
description = view.__class__.__doc__ or ''
56+
if view.description is not None:
57+
description = view.description
58+
else:
59+
description = view.__class__.__doc__ or ''
60+
5461
description = formatting.dedent(smart_text(description))
5562
if html:
5663
return formatting.markup_description(description)
@@ -107,6 +114,10 @@ def exception_handler(exc, context):
107114

108115
class APIView(View):
109116

117+
# Allow the view name and description to be set by the initkwargs.
118+
name = None
119+
description = None
120+
110121
# The following policies may be set at either globally, or per-view.
111122
renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
112123
parser_classes = api_settings.DEFAULT_PARSER_CLASSES

0 commit comments

Comments
 (0)