Django 2网址模式

时间:2018-05-11 19:57:43

标签: django django-rest-framework django-views

尝试将正确的url路径映射回Django 2中的视图。每次尝试我都会找到“未找到”的路径。

views.py

class LoginView(APIView):
    authentication_classes = ()
    permission_classes = ()

    @staticmethod
    def post(request):
        """
        Get user data and API token
        """

        user = get_object_or_404(User, email=request.data.get('email'))
        user = authenticate(username=user.email, password=request.data.get('password'))
        if user:
            serializer = UserSerializerLogin(user)
            return Response(serializer.data)
        return Response(status=status.HTTP_400_BAD_REQUEST)

main urls.py(摘录)

urlpatterns = [
    path('', include('apiV1.v1.accounts.urls')),

    path('admin/', admin.site.urls),
]

child urls.py

urlpatterns = [
    path('login', LoginView.as_view(), name='login'),
]

0 个答案:

没有答案