Skip to content

Commit 403a4b2

Browse files
pattisdrjerel
authored andcommitted
For list view, ensure 'results' in data
Closes #59
1 parent f396c89 commit 403a4b2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rest_framework_json_api/renderers.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
5757

5858
# If detail view then json api spec expects dict, otherwise a list
5959
# - http://jsonapi.org/format/#document-top-level
60-
if view and hasattr(view, 'action') and view.action == 'list':
61-
# Check for paginated results
62-
results = (data["results"] if isinstance(data, dict) else data)
60+
# The `results` key may be missing if unpaginated or an OPTIONS request
61+
if view and hasattr(view, 'action') and view.action == 'list' and \
62+
isinstance(data, dict) and 'results' in data:
63+
64+
results = data["results"]
6365

6466
resource_serializer = results.serializer
6567

0 commit comments

Comments
 (0)