Search code examples
pythondjangodjango-viewsdjango-class-based-viewsdjango-context

difference between using super() and super(ViewName,self)


I have been using in generic views (CBVs)

def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)

but I've noticed that people here do:

context = super(ClassViewName,self).get_context_data(**kwargs)

is there is a difference ?


Solution

  • The difference is python version supported syntax. In python 3 you would use

    context = super().get_context_data(**kwargs)

    while in python 2 you would use

    context = super(ClassViewName,self).get_context_data(**kwargs)

    this is true for any super method call

    see: http://www.pythonforbeginners.com/super/working-python-super-function