0

I have been working in django CBV but i am stuck and cannot reslove it i also googled that thing but nothing much i get it sometimes in classes we use super

class ArticleCounterRedirectView(RedirectView):

permanent = False
query_string = True
pattern_name = 'article-detail'

def get_redirect_url(self, *args, **kwargs):
    article = get_object_or_404(Article, pk=kwargs['pk'])
    article.update_counter()
    return super().get_redirect_url(*args, **kwargs)

class ArticleCounterRedirectView(RedirectView):

permanent = False
query_string = True
pattern_name = 'article-detail'

def get_redirect_url(self, *args, **kwargs):
    article = get_object_or_404(Article, pk=kwargs['pk'])
    article.update_counter()
    return super(ArticleCounterRedirectView,self).get_redirect_url(*args, **kwargs)

we use super to to call the parent class then in one example we give no arguments and in another we give it two arguements please can someone help me out in this

1 Answers1

1
super().get_redirect_url(*args, **kwargs)

And

super(ArticleCounterRedirectView,self).get_redirect_url(*args, **kwargs)

Both do the same thing in this case essentially,

The first one is the new syntax in python 3. If you want to explicitly bypass the MRO then you can use the second method to do that.

Hope you understood.

Arun T
  • 1,114
  • 6
  • 17
  • didnt understand what do you mean by bypass the MRO? – Ali Murtuza Jun 04 '20 at 16:46
  • 1
    MRO means the Method Resolution Order. In situations where you have multiple inheritance, a programming language has an order in which it resolves methods inside the classes. You can read more about it. By bypassing the MRO, we mean that you can bypass the programming languages default order and make some other method you want execute. – Arun T Jun 04 '20 at 17:05
  • can you please give me an example to explain this bypass MRO concept – Ali Murtuza Jun 09 '20 at 20:38
  • Check out this [answer](https://stackoverflow.com/a/3277407/9544403), it is very detailed. – Arun T Jun 09 '20 at 20:43