How do I implement user authentication in Django using rest_framework?

Viewed 15

I'm using Django/Python3 to make a simple API. I already made my models and views (also using serializers). Currently this is my login view:

class LoginView(generics.CreateAPIView):
    
    queryset = User_Login.objects.all()
    serializer_class = LoginUserSerializer

    def post(self, request, *args, **kwargs):
        id = request.data['id']
        name = request.data['name']
        password = request.data['password']
        email = request.data['email']
        User_Login.objects.create(id=id, name=name, password=password, email=email)
        
        return HttpResponse({'message': 'User Created', 'id': id}, status=200)

All my views are basic like this, just to implement a database that I previously modeled.

I need to implement authentication (the one that generates simple tokens that the user need to add to their request's header) and I know It's easy, but I followed this tutorial and I got a lot of errors.

Any advice?

0 Answers
Related