title: Django Views: Is this the correct way to use the dispatch method of a Django class based view?
body: <p>I have a class based view, and from the get and post request I have been calling a method, to obtain information from information in the HttpResponseRedirect kwargs.</p>
  
  <p>code:</p>
  
  <pre><code>class View1(View):
  
      def get(self, request, *args, **kwargs):
          ... stuff ...
  
          return render(request, self.template_name, self.context)
  
  
      def post(self, request, *args, **kwargs):
  
          ... stuff ...
  
          return HttpResponseRedirect(
              reverse('results:report_experiment',
              kwargs={
                 'sample_id': current_sample_id
                 }
               ))
  
  
  class View2(CustomView):
  
      def obtainInformation(self, kwargs):
  
          sample_id = kwargs.get('sample_id', None)
          self.sample_obj = Sample.objects.get(id=sample_id)
  
  
      def dispatch(self, request, *args, **kwargs):
  
          self.obtainInformation(kwargs)
  
          return super(View2, self).dispatch(request, *args, **kwargs)
  
  
      def get(self, request, *args, **kwargs):
          ... stuff ...
  
          return render(request, self.template_name, self.context)
  
  
  
      def post(self, request, *args, **kwargs):
  
          ... stuff ...
  
          return HttpResponseRedirect(
              reverse('results:report_experiment',
              kwargs={
                 'sample_id': current_sample_id
                 }
               ))
  </code></pre>
  
  <p>My question is, when I call self.obtainInformation(kwargs) in the dispatch method, I can access any class variables I define in BOTH the get and post methods. Previously I was calling self.obtainInformation(kwargs) in both the get and post methods of view2 (so calling the method twice). </p>
  
  <p>Is this a sensible way to use the dispatch method? </p>