0

i cant understand the meaning of the dispatch method and what is the method_decorator

class CSRFExemptMixin(object):
   @method_decorator(csrf_exempt)
   def dispatch(self, *args, **kwargs):
       return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)

can you please answer this question?

  • 1
    Does this answer your question? [what is dispatch used for in django?](https://stackoverflow.com/questions/47808652/what-is-dispatch-used-for-in-django) – kyore Mar 10 '20 at 13:00

1 Answers1

0

Dispatch is just a name of function. This function will fire when something will use this class. And method_decorator is just decorator. Decorator is a function which receive a function, make something else inside decorator and then finally execute received function.

Dmitry Yudin
  • 1,033
  • 1
  • 10
  • 31
  • thanks but i mean why do we have the dispatch func and then super().dispatch() what is this gonna do for us –  Mar 10 '20 at 12:05
  • Super will call original dispatch (not overrided by this example). Imagine Class CLS with method m1, so if you have CLS2 which inherits from CLS, and if CLS2 has a method m1, in which it has Super, so when you will call CLS2.m1() in fact it will do what it has in a CLS2 method body, and then what it has in CLS m1 method – Dmitry Yudin Mar 10 '20 at 13:28