I just deploy my Django project in cpanel and now when I want to use my RegisterView to create a user after I POST JSON data with the register field required, the user is created in the database but it gives me a
My RegisterView:
class RegisterView(APIView):
"""
Register a new user.
"""
permission_classes = [AllowAny]
def post(self, request):
"""
Getting the user's information for register.
"""
try:
email = request.data["email"]
username = request.data["username"]
password = request.data["password"]
confirm_password = request.data["confirm_password"]
full_name = request.data["full_name"]
simple_description = request.data["simple_description"]
biography = request.data["biography"]
profile_picture = request.FILES.get("profile_picture")
if User.objects.filter(email=email).exists():
return Response(data={"error": "Email has been already used."},
status=status.HTTP_400_BAD_REQUEST)
if User.objects.filter(username=username).exists():
return Response(data={"error": "Username has been already used."},
status=status.HTTP_400_BAD_REQUEST)
if password != confirm_password:
return Response(data={"error": "Passwords do not match."},
status=status.HTTP_400_BAD_REQUEST)
user = User.objects.create(
username=username,
email=email,
password=password,
full_name=full_name,
simple_description=simple_description,
biography=biography,
)
if profile_picture:
user.profile_picture = profile_picture
user.save()
Notification.objects.create(
author=user,
title="Create account",
description=CREATE_ACCOUNT_DESCRIPTION
)
return Response(data={'message': 'User has been successfully created.'},
status=status.HTTP_200_OK)
except RequestException:
return Response(data={"error": "An error occurred. Please check your internet connection."},
status=status.HTTP_503_SERVICE_UNAVAILABLE)
The JSON data i posted:
{
"email": "[email protected]",
"password": "password123",
"confirm_password": "password123",
"full_name": "John Doe",
"simple_description": "Tourist",
"biography": "I love traveling.",
"username": "johndoe"
}
I tied to create a user in the admin panel and still gives me this error