[Python] "detail": "Method \"GET\" not allowed." Django Rest Framework

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I know this question maybe a duplicate, but I have tried many solutions and could not understand any. I have followed this tutorial exactly and yet I get this error on the 'userlist' page. Everything else works just fine. Can somebody point out what the error is ?

    class UserList(APIView):
    """
    Create a new user. It's called 'UserList' because normally we'd have a get
    method here too, for retrieving a list of all User objects.
    """

    permission_classes = (permissions.AllowAny,)
    http_method_names = ['get', 'head']

    def post (self, request, format=None):
    self.http_method_names.append("GET")

    serializer = UserSerializerWithToken(data=request.data)
    if serializer.is_valid():
    serializer.save()
    return Response(serializer.data, status=status.HTTP_201_CREATED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


    EDIT: urls.py

    from django.urls import include, path
    from classroom.views.classroom import current_user, UserList
    from .views import classroom, suppliers, teachers
    urlpatterns = [path('', classroom.home, name='home'),
    path('current_user/', current_user),
    path('users/', UserList.as_view()),


    Edit:

    Still getting this error,

    [​IMG]

    Continue reading...

Compartilhe esta Página