Выдает ошибку TypeError at /api/users/subscriptions/ object of type 'function' has no len() помогите пожалуйста исправить
у меня не высвечивается мои подписки на сайте.в админке подписки видны. переходишь на сайт подписки выдает ошибку
.api/users/subscriptions/?page=1&limit=6&recipes_limit=3 500 (Internal Server Error)
value @ index.js:273
index.js:20
index.js:28
zu @ react-dom.production.min.js:262
t.unstable_runWithPriority @ scheduler.production.min.js:18
Wo @ react-dom.production.min.js:122
Lu @ react-dom.production.min.js:261
yu @ react-dom.production.min.js:243
react-dom.production.min.js:123
t.unstable_runWithPriority @ scheduler.production.min.js:18
Wo @ react-dom.production.min.js:122
qo @ react-dom.production.min.js:123
Qo @ react-dom.production.min.js:122
Re @ react-dom.production.min.js:292
Xt @ react-dom.production.min.js:73
VM510:1 Uncaught (in promise) SyntaxError: Unexpected token 'T', "TypeError "... is not valid JSON
views.py
class UserSubscribeViewSet(UserViewSet):
permission_classes = (IsAuthenticatedOrReadOnly,)
pagination_class = CustomPageNumberPagination
@action(
detail=False,
methods=('get',),
serializer_class=SubscriptionSerializer,
permission_classes=(IsAuthenticated, )
)
def subscriptions(self, request):
user = self.request.user
user_subscriptions = user.subscriber.all()
authors = [item.author.id for item in user_subscriptions]
queryset = User.objects.filter(pk__in=authors)
queryset = self.filter_queryset(queryset)
paginated_queryset = self.paginate_queryset(queryset)
serializer = self.get_serializer(paginated_queryset, many=True)
return self.get_paginated_response(serializer.data)
Перебрал все,что мог.serialazer
class SubscriptionSerializer(CustomUserSerializer):
recipes = SerializerMethodField(method_name='get_recipes')
recipes_count = SerializerMethodField(
method_name='get_recipes_count'
)
def get_srs(self):
from recipes.serializers.shortrecipes import ShortRecipeSerializer
return ShortRecipeSerializer
def get_recipes(self, obj):
author_recipes = Recipe.objects.filter(author=obj)
if 'recipes_limit' in self.context.get('request').GET:
recipes_limit = self.context.get('request').GET['recipes_limit']
author_recipes = author_recipes[:int(recipes_limit)]
if author_recipes:
serializer = self.get_srs()(
author_recipes,
context={'request': self.context.get('request')},
many=True
)
return serializer.data
return []
def get_recipes_count(self, obj):
return Recipe.objects.filter(author=obj).count()
class Meta:
model = User
fields = ('email', 'id', 'username', 'first_name', 'last_name',
'is_subscribed', 'recipes', 'recipes_count')
getSubscriptions ({ page, limit = 6, recipes_limit = 3 }) { const token = localStorage.getItem('token') return fetch( /api/users/subscriptions/?page=${page}&limit=${limit}&recipes_limit=${recipes_limit}, { method: 'GET', headers: { ...this._headers, 'authorization': Token ${token} } } ).then(this.checkResponse) }
вот показывает тут ошибка . действительно это так? Ёще код ошибок
Traceback:
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/viewsets.py" in view
125. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
509. response = self.handle_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py" in handle_exception
469. self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py" in raise_uncaught_exception
480. raise exc
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py" in dispatch
506. response = handler(request, *args, **kwargs)
File "/app/users/views.py" in subscriptions
47. paginated_queryset = self.paginate_queryset(queryset)
File "/usr/local/lib/python3.7/site-packages/rest_framework/generics.py" in paginate_queryset
171. return self.paginator.paginate_queryset(queryset, self.request, view=self)
File "/usr/local/lib/python3.7/site-packages/rest_framework/pagination.py" in paginate_queryset
204. self.page = paginator.page(page_number)
File "/usr/local/lib/python3.7/site-packages/django/core/paginator.py" in page
70. number = self.validate_number(number)
File "/usr/local/lib/python3.7/site-packages/django/core/paginator.py" in validate_number
48. if number > self.num_pages:
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/core/paginator.py" in num_pages
97. if self.count == 0 and not self.allow_empty_first_page:
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/core/paginator.py" in count
92. return len(self.object_list)
Источник: Stack Overflow на русском