title: django- why after redirecting, the form display "None"
body: <p>I have a form, after entering the information, based on infomation it filters the database and do some calculation and finally displays the result to a redirected url.</p>
  
  <p>I can indeed redirect to another url and displays the result successfully. But the issue is in the form it cannot display any data submitted by user, just show nothing for every field and the result is not based on fitered queryset. Let's say the sum, it just sum up all the columns in the database, without using the filtered result. </p>
  
  <p>I suspect that the queryset doesn't pass the filtered result to def get_context_data, therefore the queryset in get_context_data doesn't work.</p>
  
  <p>Really thank you a lot if you solve my doubt.</p>
  
  <p>(I made a EDIT version based on suggestion to combine 2 classes, hope someone can correct this EDIT version，thanks)</p>
  
  <p><a href="https://i.stack.imgur.com/ikkrw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ikkrw.jpg" alt="enter image description here"></a></p>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>url(r'^result_list/$',ResultView.as_view(),name='result'),
  url(r'^input/$',InputFormView.as_view(),name='input'),
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class InputFormView(request):
  #class InputFormView(FormView):
      template_name = 'inputform.html'
      form_class = InputForm
  
      response = HttpResponse( 'result' )
      request_form_data = request.POST #you need to sanitize/clear this data
      response.set_cookie('form_data', request_form_data)
  
  #redirect to result page with submitted form information
  
      def get_success_url(self):
          return ''.join(
          [
              reverse('result'),
              '?company=',self.request.POST.get('company'),  &lt;--do I need to change "POST" into "USER"？
              '&amp;region=',self.request.POST.get('region')
          ]
          )
  
  #class ResultView(ListView):
  class ResultView(request):
      context_object_name = 'result_list'
      template_name = 'result_list.html'
      model = Result
  
      def get_context_data(self, **kwargs):
          context = super(ResultView, self).get_context_data(**kwargs)
          context["sales"] = self.get_queryset().aggregate(Sum('sales'))
          context["company"] = self.request.POST.get("company")
          context["region"] = self.request.POST.get("region")
  
          return context
  
      def get_queryset(self):
          if self.request.method == 'POST': 
              form = InputForm(self.request.POST)
              if form.is_valid():
                  company = form.cleaned_data['company']
                  region = form.cleaned_data['region']
  
                  queryset=Result.objects.filter(region=region)
                  return queryset
          return Result.objects.all()
  
      if request.COOKIES.has_key('form_data'):
          value = request.COOKIES['form_data'] #this data also should be sanitized
  </code></pre>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;div class="basicinfo"&gt;         &lt;!--Entry Form information submitted by user--&gt;
      &lt;table border="1" cellpadding="1"&gt;
      &lt;tr&gt;
          &lt;td align="left"&gt;Company&lt;/td&gt;
          &lt;td&gt;{{ company }}&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td align="left"&gt;Region&lt;/td&gt;
          &lt;td&gt;{{ region }}&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;     
  
  &lt;!--Showing the filtered result in database--&gt;  
  &lt;td&gt;&lt;table border="0" cellspacing="10" cellpadding="10"&gt;
  &lt;tr&gt;&lt;b&gt;Sales&lt;/b&gt;&lt;/tr&gt;
  &lt;td bgcolor="#F0F0F0"&gt; {{ sales.sales__sum }}&lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;tr&gt;&lt;b&gt;Employee&lt;/b&gt;&lt;/tr&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#F0F0F0"&gt; {{ employee.employee__sum }}&lt;/td&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>EDIT- combining the 2 class views</strong></p>
  
  <pre><code>import urllib
  
  #@csrf_exempt
  
  class ResultView(ListView):
      context_object_name = 'result_list'
      template_name = 'result_list.html'
      model = Result
  
      def get_queryset(self):
          form = InputForm(self.request.GET)
          if form.is_valid():
              company = form.cleaned_data['company']
              region = form.cleaned_data['region']         
              queryset=Result.objects.filter(region=region)
              return queryset
          return Result.objects.all()
  
      def get_success_url(self):
          params = {
              'company': self.request.POST.get('company'),
              'region': self.request.POST.get('region')
          }
          return ''.join([reverse('result'), '?', urllib.urlencode(params.items())])
  
      def get_context_data(self,**kwargs):
              context = super(ResultView, self).get_context_data(**kwargs)
              context["sales"] = self.get_queryset().aggregate(Sum('sales'))         
              context["company"] = self.request.GET.get("company")
              context["region"] = self.request.GET.get("region")       
              return context
  </code></pre>
  
  <p>**EDIT- urls.py **</p>
  
  <pre><code>url(r'^result_list/$',ResultView.as_view(),name='result'),----for the result page
  url(r'^input/$',result.views.get_success_url,name='input') -----for the form, I am not sure if this line correct or not?
  </code></pre>