How to check if the email_id/ username already exists in the database in django? I want to check the existence of the email/username in the views rather than in serializer.
Following is the code:
@api_view(['POST']) def registerUser(request): f_name = request.data.get('f_name') l_name = request.data.get('l_name') username = request.data.get('username') email_id = request.data.get('email_id') password = make_password(request.data.get('password')) RegistrationRegister.objects.create( f_name = f_name, l_name = l_name, username = username , email_id = email_id, password = password, created = datetime.datetime.now().isoformat() ) return Response("User registered successfully ")
The name of the table is RegistrationRegister.
How can I validate the email and check if it exists in the db?
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.