title: Django using URL parameters to query database in class-based view
body: <p>I have a form which when submitted goes to a results page where the URL would be for example:</p>
  
  <pre><code>appname/results/?make=BMW
  </code></pre>
  
  <p>I want to use the URL parameters to query database and display the results on that page.</p>
  
  <p>This is the code I have so far:</p>
  
  <p>views</p>
  
  <pre><code>class SearchView(FormView):
  
      template_name = 'carproject/search.html'
  
      def get(self, request, *args, **kwargs):
          form = AdvancedSearch(self.request.GET or None)
          context = {'form': form}
          if form.is_valid():
              return render(request, 'carproject/results.html')
          else:
              return render(request, self.template_name, context)
  
  class ResultsView(TemplateView):
      template_name = 'carproject/results.html'
  
      def get_queryset(self, request, *args, **kwargs):
          make = self.request.GET.get('make')
          results = Vehicles.objects.filter(makename__icontains='make')
          context = {'results': results}
  
          return render(request, self.template_name, context)
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;table&gt;
  {% for item in results%}
                  &lt;tr&gt;
                      &lt;td&gt;{{item.makename}}&lt;/td&gt;
                      &lt;td&gt;{{item.model}}&lt;/td&gt;
                      &lt;td&gt;{{item.seriesname}}&lt;/td&gt;
                      &lt;td&gt;{{item.seatingcapacity}}&lt;/td&gt;
                      &lt;td&gt;{{item.pricenew}}&lt;/td&gt;
                  &lt;/tr&gt;
                  {% endfor %}
  &lt;/table&gt;
  </code></pre>