title: What is dispatch used for in django?
body: <p>I have been trying to wrap my head around the dispatch method, particularly in Django. However, I cannot seem to figure out exactly what it does. I tried to gain an understanding from the Django docs but didn't find them to informative on this topic. Per my understanding it is a listener that listens to all events happening on a page but I am not sure if this is the case?</p>
  <pre class="lang-py prettyprint-override"><code>class OrderDetail(DetailView):
      model = Order
  
      def **dispatch**(self, request, *args, **kwargs):
          try:
              user_check_id = self.request.session.get(&quot;user_checkout_id&quot;)
              user_checkout = UserCheckout.objects.get(id=user_check_id)
          except UserCheckout.DoesNotExist:
              user_checkout = UserCheckout.objects.get(user=request.user)
          except:
              user_checkout = None
  
          obj = self.get_object()
          if obj.user == user_checkout and user_checkout is not None:
              return super(OrderDetail, self).dispatch(request, *args, **kwargs)
          else:
              raise Http404
  </code></pre>