title: Django & AJAX search view giving me KeyError
body: <p>I'm adding an AJAX search feature to my Django blog application.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>search_form.html</strong></p>
  
  <pre><code>&lt;form id="search-form" method="get" action="{% url 'search' %}"&gt;
      &lt;input type="text" name="q" /&gt;
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;div id="search-results"&gt;
      {% include "post_list.html" %}    //html file which simply views all the requested posts
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>search.js</strong></p>
  
  <pre><code>function search_submit() {
      var query = $("#id_query").val();
  
      $("#search-results").load(
          "/search/?q=" + encodeURIComponent(query)
      );
  
      return false;
  }
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class PostSearch(ListView):
      model = Post
      template_name = 'search_form.html'
      context_object_name = 'post_list'
  
      def get(self, request, *args, **kwargs):
          if self.request.is_ajax():              
              return self.render_to_response('post_list.html', self.get_context_data(**kwargs))
          else:
              return self.render_to_response(self.template_name, self.get_context_data(**kwargs))
  
      def get_queryset(self):
          queryset = super(TitleSearchMixin, self).get_queryset()
  
          q = self.request.GET.get('q')
  
          if q:
              return queryset.filter(question_title__icontains=q)
  </code></pre>
  
  <p>So basically, my QuestionSearch view just returns a "post_list.html" which is a template for viewing multiple posts for an AJAX request, while returning the whole "search_form.html" when it is a normal request. For some reason, this is giving me the error:</p>
  
  <p><strong>ERROR:</strong></p>
  
  <pre><code>KeyError at /search/
  u'object_list'
  </code></pre>
  
  <p>Since I am stuck, I have 2 questions..</p>
  
  <p>(1) Why is this error occurring?</p>
  
  <p>(2) Is my implementation of the search feature even done in the right way..? I've been reading about RESTf API design, yet I'm not sure whether mine is "RESTful" or not :((</p>
  
  <p>Thanks!!!</p>