From 0a2846d580f17cdce6df30217bc48a6c2e7ea0b0 Mon Sep 17 00:00:00 2001 From: Pierre Chiquet Date: Fri, 10 Mar 2017 14:26:43 +0100 Subject: [PATCH] Interactive doc: remove document.data.items from templates "document_data_list" list of pairs is directly passed in template context, so that we can use dictionaries with "items" as key (i.e.: data['items']) Before this change, with the following Router config: api_router.register(r'items', ItemViewSet) GET /docs/ failed with error: Internal Server Error: /docs/ ... File "C:\Users\User\py-envs\ubiserver\lib\site-packages\django\template\defaulttags.py", line 200, in render .format(num_loopvars, len_item), ValueError: Need 2 values to unpack in for loop; got 4. see https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#for --- rest_framework/renderers.py | 5 ++++- rest_framework/templates/rest_framework/docs/document.html | 2 +- rest_framework/templates/rest_framework/docs/sidebar.html | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 206dc0ccf..ff624e600 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -805,8 +805,11 @@ class DocumentationRenderer(BaseRenderer): languages = ['shell', 'javascript', 'python'] def get_context(self, data, request): + document = data + document_data_list = document.data.items() return { - 'document': data, + 'document': document, + 'document_data_list': document_data_list, 'langs': self.languages, 'code_style': pygments_css(self.code_style), 'request': request diff --git a/rest_framework/templates/rest_framework/docs/document.html b/rest_framework/templates/rest_framework/docs/document.html index c2dcb3ddc..1800ad59b 100644 --- a/rest_framework/templates/rest_framework/docs/document.html +++ b/rest_framework/templates/rest_framework/docs/document.html @@ -14,7 +14,7 @@ -{% for section_key, section in document.data.items %} +{% for section_key, section in document_data_list %} {% if section_key %}

{{ section_key }}

diff --git a/rest_framework/templates/rest_framework/docs/sidebar.html b/rest_framework/templates/rest_framework/docs/sidebar.html index 6f4de8ee1..800eba6b9 100644 --- a/rest_framework/templates/rest_framework/docs/sidebar.html +++ b/rest_framework/templates/rest_framework/docs/sidebar.html @@ -4,7 +4,7 @@