drf-yasg
drf-yasg copied to clipboard
Returned a template response with no `template_name` attribute set on either the view or response
Hi, I setup everything as per the docs but I'm getting this error and I can't find whats causing it. I went through the docs and there is nothing I can use from there. There was an issue on drf-yasg (https://github.com/axnsan12/drf-yasg/issues/532) that was closed by the person who opened it with no solution given.
- drf-yasg2==1.18.5
- djangorestframework==3.8.0
- Django==2.0.1
Internal Server Error: /swagger/
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 158, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
response = response.render()
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\response.py", line 72, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\drf_yasg2\renderers.py", line 79, in render
swagger, accepted_media_type, renderer_context
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\renderers.py", line 168, in render
template_names = self.get_template_names(response, view)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\renderers.py", line 197, in get_template_names
'Returned a template response with no `template_name` attribute set on either the view or response'
django.core.exceptions.ImproperlyConfigured: Returned a template response with no `template_name` attribute set on either the view or response
[16/Oct/2020 00:39:23] "GET /swagger/ HTTP/1.1" 500 112354
urls.py
from rest_framework import permissions
from drf_yasg2.views import get_schema_view
from drf_yasg2 import openapi
schema_view = get_schema_view(
openapi.Info(
title="Snippets API",
default_version='v1',
description="Test description",
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
settings.py
INSTALLED_APPS = [
'rest_framework',
'myappname',
'rest_framework.authtoken',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'fcm_django',
'storages',
'colorfield',
'drf_yasg2',
]
I cannot recreate this issue. Can you verify your installation is 1.18.5+?