title: How to return JsonResponse in Django generic ListView
body: <p>I'm having trouble returning a valid <code>HttpResponse</code> in my <code>ListView</code> (and am getting a <code>ValueError: The view didn't return an HttpResponse object...</code>. I've overridden <code>get</code> because I want to return a JsonResponse:</p>
  
  <pre><code>def get(self, requets, *args, **kwargs):
      queryset = self.get_queryset()
      data = serializers.serialize("json", queryset)
      return JsonResponse(data, status=200, safe=False)
  </code></pre>
  
  <p>I've checked that <code>queryset</code> and <code>data</code> and the <code>JsonResponse</code> are not <code>None</code>.
  Changing the return statement doesn't work:</p>
  
  <pre><code>return HttpResponse(json.dumps(data), content_type="application/json", status=200)
  </code></pre>
  
  <p>Previously, if I ever needed to override <code>get</code>, I would <code>return render(...)</code>, which works.</p>
  
  <p>So, why is my <code>HttpResponse</code> or <code>JsonResponse</code> not an acceptable HttpResponse as per the error in this instance? The GET request will be an ajax request, and I do need to provide some sensible json in reply. </p>
  
  <p>Edit: full class</p>
  
  <pre><code>from django.core import serializers
  from django.http import JsonResponse
  @method_decorator(login_required, name='dispatch')
  class AjaxQuestionList(ListView):
      """
      Generic ListView for Question objects. Called by front-end app.
      Requires hash url parameter to identify Survey.
      Intended to be called via ajax. Returns serialized json list of Questions.
      """
      http_method_names = ['get',]
  
      def dispatch(self, request, *args, **kwargs):
          #allow user to call this View if their Client owns the Survey
          self.survey = get_object_or_404(Survey, hash=self.kwargs['hash'])
          up = get_object_or_404(UserProfile, fk_user=self.request.user)
          self.client = up.fk_client
          if self.survey.fk_client != self.client:
              raise Http404
          super(AjaxQuestionList, self).dispatch(request, *args, **kwargs)
  
      def get_queryset(self):
          return Question.objects.filter(fk_survey=self.survey)
  
      def get(self, request, *args, **kwargs):
          queryset = self.get_queryset()
          data = serializers.serialize("json", queryset)
          return JsonResponse(data, status=200, safe=False)
  </code></pre>
  
  <p>Traceback:</p>
  
  <blockquote>
    <p>File
    "/webapps/escher/lib/python3.5/site-packages/django/core/handlers/exception.py"
    in inner
      39.             response = get_response(request)</p>
    
    <p>File
    "/webapps/escher/lib/python3.5/site-packages/django/core/handlers/base.py"
    in _legacy_get_response
      249.             response = self._get_response(request)</p>
    
    <p>File
    "/webapps/escher/lib/python3.5/site-packages/django/core/handlers/base.py"
    in _get_response
      198.                 "returned None instead." % (callback.<strong>module</strong>, view_name)</p>
    
    <p>Exception Type: ValueError at /si/survey/123456789/ajax-question-list/
    Exception Value: The view myapp.views.survey.AjaxQuestionList
    didn't return an HttpResponse object. It returned None instead.</p>
  </blockquote>
  
  <p>From the <a href="https://docs.djangoproject.com/en/1.10/ref/class-based-views/flattened-index/#list-views" rel="nofollow">CBV flattened index</a> I just assumed that <code>render_to_response()</code> was called automatically after <code>get()</code>, rendering whatever HttpResponse <code>get()</code> returned. Am I mistaken?</p>