mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Display the media type of the API response on the browsable API
This commit is contained in:
parent
6e92e415aa
commit
6cd0394e20
|
@ -427,7 +427,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
files = request.FILES
|
files = request.FILES
|
||||||
except ParseError:
|
except ParseError:
|
||||||
data = None
|
data = None
|
||||||
files = None
|
files = None
|
||||||
else:
|
else:
|
||||||
data = None
|
data = None
|
||||||
files = None
|
files = None
|
||||||
|
@ -544,6 +544,14 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
raw_data_patch_form = self.get_raw_data_form(view, 'PATCH', request)
|
raw_data_patch_form = self.get_raw_data_form(view, 'PATCH', request)
|
||||||
raw_data_put_or_patch_form = raw_data_put_form or raw_data_patch_form
|
raw_data_put_or_patch_form = raw_data_put_form or raw_data_patch_form
|
||||||
|
|
||||||
|
response_headers = dict(response.items())
|
||||||
|
renderer_content_type = ''
|
||||||
|
if renderer:
|
||||||
|
renderer_content_type = '%s' % renderer.media_type
|
||||||
|
if renderer.charset:
|
||||||
|
renderer_content_type += ' ;%s' % renderer.charset
|
||||||
|
response_headers['Content-Type'] = renderer_content_type
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'content': self.get_content(renderer, data, accepted_media_type, renderer_context),
|
'content': self.get_content(renderer, data, accepted_media_type, renderer_context),
|
||||||
'view': view,
|
'view': view,
|
||||||
|
@ -555,6 +563,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
'breadcrumblist': self.get_breadcrumbs(request),
|
'breadcrumblist': self.get_breadcrumbs(request),
|
||||||
'allowed_methods': view.allowed_methods,
|
'allowed_methods': view.allowed_methods,
|
||||||
'available_formats': [renderer.format for renderer in view.renderer_classes],
|
'available_formats': [renderer.format for renderer in view.renderer_classes],
|
||||||
|
'response_headers': response_headers,
|
||||||
|
|
||||||
'put_form': self.get_rendered_html_form(view, 'PUT', request),
|
'put_form': self.get_rendered_html_form(view, 'PUT', request),
|
||||||
'post_form': self.get_rendered_html_form(view, 'POST', request),
|
'post_form': self.get_rendered_html_form(view, 'POST', request),
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="response-info">
|
<div class="response-info">
|
||||||
<pre class="prettyprint"><div class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
|
<pre class="prettyprint"><div class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
|
||||||
{% for key, val in response.items %}<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize_quoted_links }}</span>
|
{% for key, val in response_headers.items %}<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize_quoted_links }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>{{ content|urlize_quoted_links }}</pre>{% endautoescape %}
|
</div>{{ content|urlize_quoted_links }}</pre>{% endautoescape %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -256,6 +256,18 @@ class RendererEndToEndTests(TestCase):
|
||||||
self.assertEqual(resp.get('Content-Type', None), None)
|
self.assertEqual(resp.get('Content-Type', None), None)
|
||||||
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
|
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
def test_contains_headers_of_api_response(self):
|
||||||
|
"""
|
||||||
|
Issue #1437
|
||||||
|
|
||||||
|
Test we display the headers of the API response and not those from the
|
||||||
|
HTML response
|
||||||
|
"""
|
||||||
|
resp = self.client.get('/html1')
|
||||||
|
self.assertContains(resp, '>GET, HEAD, OPTIONS<')
|
||||||
|
self.assertContains(resp, '>application/json<')
|
||||||
|
self.assertNotContains(resp, '>text/html; charset=utf-8<')
|
||||||
|
|
||||||
|
|
||||||
_flat_repr = '{"foo": ["bar", "baz"]}'
|
_flat_repr = '{"foo": ["bar", "baz"]}'
|
||||||
_indented_repr = '{\n "foo": [\n "bar",\n "baz"\n ]\n}'
|
_indented_repr = '{\n "foo": [\n "bar",\n "baz"\n ]\n}'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user