title: Django DRF TemplateHMLRenderer
body: <p>Trying to display the django rest framework data in an html template:</p>
  
  <p><strong>view.py</strong></p>
  
  <pre><code>class TestView(viewsets.ModelViewSet):
      """ test rest"""
      queryset = models.Pippo.objects.all()
      serializer_class = PippoSerializer
      renderer_classes = (JSONRenderer, TemplateHTMLRenderer)
      template_name = 'pippo_app/test.html'
  </code></pre>
  
  <p><strong>url.py</strong></p>
  
  <pre><code>app_name = 'pippo_app'
  router = routers.DefaultRouter()
  router.register(r'ertest', views.PippoView)
  </code></pre>
  
  <p><strong>template.html</strong></p>
  
  <pre><code>{% load rest_framework %}
  
  &lt;html&gt;&lt;body&gt;
  
  &lt;h1&gt;Profile - {{ dim_spessore }}&lt;/h1&gt;
  
  {{ form }}
  
  
  &lt;form action="{% url 'pippo_app:pippo-list' %}" method="post"&gt;
  
  
      {% csrf_token %}
      {% render_form serializer %}
      &lt;input type="submit" value="Save" /&gt;
  &lt;/form&gt;
  
  
  
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>result in :</p>
  
  <blockquote>
    <p>builtins.AttributeError AttributeError: 'str' object has no attribute
    'data'</p>
  </blockquote>
  
  <p>the Json call works:</p>
  
  <blockquote>
    <p>Response 200 Status: Ok</p>
  </blockquote>
  
  <p>adding the complete traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "venv/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
      return self.application(environ, start_response)
    File "venv/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in get_response
      response = self._middleware_chain(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/utils/deprecation.py", line 140, in __call__
      response = self.get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 43, in inner
      response = response_for_exception(request, exc)
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
      response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
      return debug.technical_500_response(request, *exc_info)
    File "venv/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
      six.reraise(exc_type, exc_value, tb)
    File "venv/lib/python3.5/site-packages/six.py", line 693, in reraise
      raise value
    File "venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
      response = get_response(request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
      response = response.render()
    File "venv/lib/python3.5/site-packages/django/template/response.py", line 107, in render
      self.content = self.rendered_content
    File "venv/lib/python3.5/site-packages/rest_framework/response.py", line 72, in rendered_content
      ret = renderer.render(self.data, accepted_media_type, context)
    File "venv/lib/python3.5/site-packages/rest_framework/renderers.py", line 176, in render
      return template.render(context, request=request)
    File "venv/lib/python3.5/site-packages/django/template/backends/django.py", line 66, in render
      return self.template.render(context)
    File "venv/lib/python3.5/site-packages/django/template/base.py", line 207, in render
      return self._render(context)
    File "venv/lib/python3.5/site-packages/django/test/utils.py", line 107, in instrumented_test_render
      return self.nodelist.render(context)
    File "venv/lib/python3.5/site-packages/django/template/base.py", line 990, in render
      bit = node.render_annotated(context)
    File "venv/lib/python3.5/site-packages/django/template/base.py", line 957, in render_annotated
      return self.render(context)
    File "venv/lib/python3.5/site-packages/django/template/library.py", line 203, in render
      output = self.func(*resolved_args, **resolved_kwargs)
    File "venv/lib/python3.5/site-packages/rest_framework/templatetags/rest_framework.py", line 85, in render_form
      return renderer.render(serializer.data, None, {'style': style})
  AttributeError: 'str' object has no attribute 'data'
  </code></pre>
  
  <p>Now I've enabled werkzeug debugger and I can see that serializer is '', so there's isn't data at all.</p>
  
  <p>Another way to make the frontend to this API:</p>
  
  <pre><code>class Manage(TemplateView):
      """test HTML frontend """
      template_name = 'label_app/label_MAN_form.html'
  
      def get_context_data(self, **kwargs):
          context = super(Manage, self).get_context_data(**kwargs)
          context['prova'] = serializers.PippoSerializer()   
          return context
  </code></pre>
  
  <p>with this <strong>template.html</strong></p>
  
  <pre><code>{{prova}}
  </code></pre>
  
  <p>I can see data form serializer.</p>
  
  <p>This is the correct approach?</p>