[Mixins] - Order of the Mixins - Is it a bug?

已查看 65 次
跳至第一个未读帖子

Vinnicyus Gracindo

未读,
2018年6月15日 13:36:472018/6/15
收件人 django-d...@googlegroups.com
Hi. I beat my brains out trying to find out why my cbv was not working with LoginRequiredMixin.
I found the order of the mixins in the inheritance:
It works: class UserListView(LoginRequiredMixin, ListView) 
Doesn't work:  class UserListView(ListView, LoginRequiredMixin

Is that how it was designed? or is it a bug?

Thanks.

Markus Holtermann

未读,
2018年6月15日 13:50:152018/6/15
收件人 django-d...@googlegroups.com
Hi Vinnicyus,

this is by design.

There's an interesting talk by Ana Balica on Mixins in Django: https://www.youtube.com/watch?v=rMn2wC0PuXw

/Markus
>--
>You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
>To post to this group, send email to django-d...@googlegroups.com.
>Visit this group at https://groups.google.com/group/django-developers.
>To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMjWKi8LdUEwBnTfPX43x%3D5DWUam74dy-eVBof5%2BJmGOr1SLYQ%40mail.gmail.com.
>For more options, visit https://groups.google.com/d/optout.

jackotonye

未读,
2018年6月15日 16:52:222018/6/15
收件人 Django developers (Contributions to Django itself)
By design mixins are applied in the order they are inherited.

`class A: pass`
`class B: pass`

```
class C(A, B):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # This will call A.__init__() then B.__init__()


```

Vinnicyus Gracindo

未读,
2018年6月16日 10:31:092018/6/16
收件人 django-d...@googlegroups.com
I understood now. Thank you so much. 

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
回复全部
回复作者
转发
0 个新帖子