Question: I have the code and error stacktrace below. I am trying to access localhost:8000/fundamentals/ but I get the error 'list' object has no attribute 'values' error web_1 | Traceback (most recent call last): web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner web_1 | response = get_response(request) web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 202, in _get_response web_1 | response = response.render() web_1 | File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 105, in render web_1 | self.content = self.rendered_content web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/response.py", line 70, in rendered_content web_1 | ret = renderer.render(self.data, accepted_media_type, context) web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 724, in render web_1 | context = self.get_context(data, accepted_media_type, renderer_context) web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 655, in get_context web_1 | raw_data_post_form = self.get_raw_data_form(data, view, 'POST', request) web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 563, in get_raw_data_form web_1 | data = serializer.data.copy() web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 562, in data web_1 | ret = super().data web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 264, in data web_1 | self._data = self.get_initial() web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 412, in get_initial web_1 | for field in self.fields.values() web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 413, in <listcomp> web_1 | if not field.read_only web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 412, in get_initial web_1 | for field in self.fields.values() web_1 | AttributeError: 'list' object has no attribute 'values' web_1 | [05/Sep/2020 11:42:59] "GET /fundamentals/ HTTP/1.1" 500 99118  models/fundamentals.py  7 class Fundamentals(models.Model): 8 balance_sheet = models.ForeignKey(BalanceSheet, on_delete=models.CASCADE) 9 ticker = models.ForeignKey(Stock, on_delete=models.CASCADE) 10 slug = models.SlugField(default="", editable=False) 11 12 def save(self, *args, **kwargs): 13 value = self.ticker 14 self.slug = slugify(value, allow_unicode=True) 15 super().save(*args, **kwargs) 16 17 def __str__(self): 18 return {f"{self.ticker} fundamentals"} 19 20 class Meta: 21 verbose_name = "fundamentals" 22 verbose_name_plural = "fundamentals"  views.py  13 class FundamentalsViewSet(viewsets.ModelViewSet): 14 queryset = Fundamentals.objects.all() 15 serializer_class = FundamentalsSerializer 16 # lookup_url_kwarg = "ticker" 17 # lookup_field = "ticker__iexact" 18 19 def get_balance_sheets(self, requests, *args, **kwargs): 20 bs_qs = BalanceSheet.objects.filter(ticker=self.get_object()) 21 serializer = BalanceSheetSerializer(bs_qs) 22 return Response(serializer.data)  serializers.py 307 class BalanceSheetSerializer(serializers.ModelSerializer): 308 assets = AssetsSerializer() 309 liab_and_stock_equity = LiabAndStockEquitySerializer() 310 311 fields = [ 312 "ticker", 313 "periodicity", 314 "assets", 315 "liab_and_stock_equity", 316 "end_date", 317 "start_date", 318 ] 321 class FundamentalsSerializer(serializers.ModelSerializer): 322 balance_sheet = BalanceSheetSerializer() 323 324 class Meta: 325 model = Fundamentals 326 fields = ["balance_sheet"]  urls.py  17 router = DefaultRouter() 18 router.register(r"fundamentals", views.FundamentalsViewSet) 19 urlpatterns = router.urls 

Answer: The issue here is with the BalanceSheetSerializer. The fields must be defined within class Meta instead of defining it as class variable.  class BalanceSheetSerializer(serializers.ModelSerializer): class Meta: fields = [your_fields]