ReturnDict object not callable Django Rest Framework

I am new to both SO and Django DRF. Whenever I try running the code. I get the error "TypeError ReturnDict object not callable".

from __future__ import unicode_literals

from django.db import models

# Create your models here.

class Fish(models.Model):
    active = models.BooleanField()

from  fishes.models import  Fish
from  rest_framework import  serializers

class FishSerializers(serializers.ModelSerializer):

    def is_successful(self,obj):
        return self.context.get('value')

    class Meta:
        fields=('name', 'active', 'created','success')

from django.shortcuts import render
from  rest_framework import viewsets
from rest_framework import permissions
from  fishes.serializers import FishSerializers
from fishes.models import  Fish
# Create your views here.

class FishViewSets(viewsets.ModelViewSet):
    queryset = Fish.objects.get(id=2)
    serializer_class = FishSerializers(queryset,context={'value':'brother'}).data

from django.conf.urls import url,include
from django.contrib import admin
from rest_framework import  routers
from fishes import  views

router= routers.DefaultRouter()
urlpatterns = [
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))


Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/", line 87, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/", line 47, in list
    serializer = self.get_serializer(queryset, many=True)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/", line 111, in get_serializer
    return serializer_class(*args, **kwargs)
TypeError: 'ReturnDict' object is not callable

Please help to understand and resolve this error in django rest framework!


There are at least two problems is in your FishViewSets.

  1. queryset should be a queryset (you set a single instance)

  2. serializer_class has to be a class. You set it to a serialized instance of your serializer.

This should help:

class FishViewSets(viewsets.ModelViewSet):
    queryset = Fish.objects.all()
    serializer_class = FishSerializers

Need Your Help

Parse text to a CSV-file with PHP

php csv export-to-csv fputcsv

I want to parse text from my database into a CSV-file with PHP. The problem is that nothing is parsed to the file.

Robot Framework - Can't set Object for Attribute using Execute JavaScript

javascript selenium-webdriver robotframework

I want to set Object for value attribute using Execute Javascript but it doesn't work with robot framework (it work with C#)