Django __init__() got an unexpected keyword argument 'any' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Django __init__() got an unexpected keyword argument 'any' (/thread-35652.html) |
Django __init__() got an unexpected keyword argument 'any' - ikurorox - Nov-26-2021 I do not understand what happened to my application, I was trying to obtain the detail of a user with email field, now I can't list the users that I have registered in the database, it is giving me this error: I commented all the code and let the get function to list the users but it doesn't work Quote:TypeError at /users/ view.py from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response from src.apps.account.models import CustomUser from src.apps.account.serializer import CustomUserSerializer class UserList(APIView): def get(self, request, format=None, users=None): users = CustomUser.objects.all() serialized_users = CustomUserSerializer(users, any=True) return Response(serialized_users.data, status=status.HTTP_200_OK) # class UserRegister(APIView): # def post(self, request): # # user_info = request.data # serialized_user = CustomUserSerializer(data=request.data) # if serialized_user.is_valid(): # new_user = serialized_user.save() # new_user.set_password(new_user.password) # new_user.save() # return Response(new_user, status=status.HTTP_201_CREATED) # return Response(serialized_user.errors) # class UserDetail(APIView): # def get(self, request, pk): # user_detail = CustomUser.objects.get(email=pk) # serialized_detail = CustomUserSerializer(user_detail) # return Response(serialized_detail.data)url.py from django.urls import path from . import views from src.apps.account.views import UserList urlpatterns = [ path("users/", UserList.as_view(), name="user-list"), # path("users/register/", UserRegister.as_view(), name="user-new"), # path("users/detail/<str:email>", UserDetail.as_view(), name="user-detail") ]CustomUserSerializer from rest_framework import serializers from rest_framework import status from rest_framework.response import Response from .models import CustomUser class CustomUserSerializer(serializers.ModelSerializer): class Meta: model = CustomUser fields = "__all__" extra_kwargs = {"password": {"write_only": True}}why am i getting this error? RE: Django __init__() got an unexpected keyword argument 'any' - ghoul - Nov-26-2021 You probably meant to pass 'many' and not 'any' to the serializer. class UserList(APIView): def get(self, request, format=None, users=None): users = CustomUser.objects.all() serialized_users = CustomUserSerializer(users, many=True) return Response(serialized_users.data, status=status.HTTP_200_OK) RE: Django __init__() got an unexpected keyword argument 'any' - ikurorox - Nov-26-2021 Thats the problem!! typed error, thank you!!!! |