Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned a template response with no template_name attribute set on either the view or response #49

Open
ejfilip opened this issue Oct 15, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@ejfilip
Copy link

ejfilip commented Oct 15, 2020

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 (axnsan12#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',
]
@JoelLefkowitz
Copy link
Owner

I cannot recreate this issue. Can you verify your installation is 1.18.5+?

@JoelLefkowitz JoelLefkowitz added the bug Something isn't working label Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants