question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Views do not have a serializer_class

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jonpavelichcommented, Apr 6, 2018

You’re right, subclassing APIView instead of GenericAPIView fixes this issue. Creating a PR now 😃

0reactions
belugamecommented, Nov 24, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django rest framework, use different serializers in the same ...
Basically I detect when the user is requesting a list view or a detailed view and change serializer_class to suit my needs. I...
Read more >
Serializers - Django REST framework
We provide a Serializer class which gives you a powerful, generic way to control the output of your responses, as well as a...
Read more >
Creating views and serializers — Django Rest Framework
We'll learn basic knowledge about serializers, views and url patterns. ... The only difference is using ViewSet you don't have to create ...
Read more >
Implement a base serializer class for API views #12 - GitHub
Django-rest-framework, which has been used to create API views, does not call the full_clean method under models, this means that custom ...
Read more >
Django REST Framework Views - Generic Views - TestDriven.io
All classes that extend from a concrete view need: queryset; serializer class. Additionally, you can provide policy attributes, as explained in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found