budjeto/authentication/views.py

20 lines
637 B
Python
Raw Permalink Normal View History

2024-02-06 10:21:09 +00:00
from django.shortcuts import render
from django.contrib.auth import get_user_model
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from authentication import serializers
class SignUpView(APIView):
def post(self, request):
user = serializers.UserSerializer(data=request.data)
if user.is_valid():
u = user.save()
u.set_password(request.data['password'])
u.save()
return Response(user.data, status=status.HTTP_201_CREATED)
return Response(user.errors, status=status.HTTP_400_BAD_REQUEST)