How to check if the email/username already exists in the db in django?


This Content is from Stack Overflow. Question asked by Ritika

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:


def registerUser(request):        
        f_name ='f_name')
        l_name ='l_name')
        username ='username')
        email_id ='email_id')
        password = make_password('password'))
            f_name = f_name, 
            l_name = l_name,
            username = username , 
            email_id = email_id,
            password = password,
            created =
        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.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?