Views do not have a serializer_class
See original GitHub issueI am attempting to use django-rest-swagger for API documentation with DRF 3.8.1. Loading fails with the following exception:
'LoginView' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method.
In the DRF documentation, it specifies that:
serializer_class
- […] Typically, you must either set this attribute, or override the get_serializer_class() method.
http://www.django-rest-framework.org/api-guide/generic-views/#attributes
If I’m understanding the documentation correctly, it appears that DRF GenericAPIView
must have a serializer_class
, which LoginView
, LogoutView
, and LogoutAllView
do not, so I believe this is a bug in django-rest-knox and not in django-rest-swagger.
I’m going to override the classes in my project to add a serializer_class
, but I think it might be a fairly involved set of changes. If you’re interested in a pull request, please let me know and I can work on creating one once I make the changes.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
You’re right, subclassing
APIView
instead ofGenericAPIView
fixes this issue. Creating a PR now 😃Is this your code that you posted, @opeeny? Try changing the class to “class LoginView(APIView):” and add a serializer_class attribute like you see in this snippet for example https://www.django-rest-framework.org/tutorial/3-class-based-views/#using-generic-class-based-views