生成Django路由

时间:2017-10-03 08:23:21

标签: python django django-rest-auth

请告诉我,为什么路线没有正确生成?

视图集:

class MyViewSet(BaseViewSet, CreateModelMixin):
    http_method_names = ['post']

    queryset = User.objects

    serializer_class = MySerializer
    permission_classes = (AllowAny,)


    @detail_route(methods=['get'], permission_classes=[IsAuthenticated], url_name='my')
    def my(self, request, version, pk=None):
        serializer = MyInfoSerializer(data=request.data, context={'request': request})

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

网址:

users_router = DefaultRouter()
users_router.register(r'users', MyViewSet)

当您尝试导航到指定的地址(http://127.0.0.1:8000/api/v1/users/my/)时,会出现第404页。路线形成如下:

^api/ ^(?P<version>(v1))/ ^ ^users/$ [name='user-list']
^api/ ^(?P<version>(v1))/ ^ ^users\.(?P<format>[a-z0-9]+)/?$ [name='user-list']
^api/ ^(?P<version>(v1))/ ^ ^users/(?P<pk>[^/.]+)/my/$ [name='user-my']
^api/ ^(?P<version>(v1))/ ^ ^users/(?P<pk>[^/.]+)/my\.(?P<format>[a-z0-9]+)/?$ [name='user-my'] 

0 个答案:

没有答案