generic views or viewsets with mixins, which is the better choice?

239 views
Skip to first unread message

Sagar Bhadarka

unread,
Jul 19, 2018, 6:54:05 AM7/19/18
to Django REST framework
Hello everyone,
I want to insert user registration data in database and currently I did that using generic views. But I think that may be viewsets is better option. I don't have any previous experience with django. so can anyone explain which is the better choice. And if viewsets is better choice then should i use mixins?
I have look at documentation and other articles as well. But still I'm little confused. I'm sure that each of them has their own advantages and disadvantages. Can anyone explain in which situation what is the better option?

Jason

unread,
Jul 19, 2018, 7:04:49 AM7/19/18
to Django REST framework
Well, viewsets are an abstraction that take in mixins, as you can see https://github.com/encode/django-rest-framework/blob/master/rest_framework/viewsets.py#L209-L228.  Generic views themselves are made of the same mixins, as you can see at https://github.com/encode/django-rest-framework/blob/master/rest_framework/generics.py#L186-L293

basically, use viewsets if you're implementing a highly standard API that doesn't deviate much from the default implementation features in DRF. Otherwise, if you need customization and specific things, then implementing a generic view and overriding would be better.  It all depends on your use case.
Reply all
Reply to author
Forward
0 new messages