diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 0198f3e8c..a7508bb7c 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -812,6 +812,7 @@ class DocumentationRenderer(BaseRenderer): format = 'html' charset = 'utf-8' template = 'rest_framework/docs/index.html' + error_template = 'rest_framework/docs/error.html' code_style = 'emacs' languages = ['shell', 'javascript', 'python'] @@ -824,9 +825,19 @@ class DocumentationRenderer(BaseRenderer): } def render(self, data, accepted_media_type=None, renderer_context=None): - template = loader.get_template(self.template) - context = self.get_context(data, renderer_context['request']) - return template.render(context, request=renderer_context['request']) + if isinstance(data, coreapi.Document): + template = loader.get_template(self.template) + context = self.get_context(data, renderer_context['request']) + return template.render(context, request=renderer_context['request']) + else: + template = loader.get_template(self.error_template) + context = { + "data": data, + "request": renderer_context['request'], + "response": renderer_context['response'], + "debug": settings.DEBUG, + } + return template.render(context, request=renderer_context['request']) class SchemaJSRenderer(BaseRenderer): diff --git a/rest_framework/templates/rest_framework/docs/error.html b/rest_framework/templates/rest_framework/docs/error.html new file mode 100644 index 000000000..15bfb1037 --- /dev/null +++ b/rest_framework/templates/rest_framework/docs/error.html @@ -0,0 +1,75 @@ +{% load staticfiles %} + + +
+ + + + ++{{ data }} ++ + +{% if debug is True %} +
Note: You are seeing this message because DEBUG==True
.
Seeing this page is usually a configuration error: are your
+DEFAULT_AUTHENTICATION_CLASSES
or DEFAULT_PERMISSION_CLASSES
+being applied unexpectedly?
Your response status code is: {{ response.status_code }}
Most commonly the intended solution is to disable authentication and permissions +when including the docs urls:
+ ++ url(r'^docs/', include_docs_urls(title='Your API', + authentication_classes=[], + permission_classes=[])), ++ + +
If you wish access to your docs to be authenticated you may override this template
+at rest_framework/docs/error.html
.
The available context is: data
the error dict above, request
,
+response
and the debug
flag.