title: How to do validation in django serializers?
body: <p>I have 2 custom validation functions created using packages from PyPI, I want to inlcude them in my serializers.py in my django project before converting  it to JSON using rest. Problem is i dont know where or how to put the functions in such that the code will run through it. Here is my code:
  <a href="https://i.stack.imgur.com/Q6Jgt.png" rel="nofollow noreferrer">enter image description here</a>(this is how im adding users right now, using the model's fields ive registered)
  Here is my code:</p>
  
  <pre><code>/* serializers.py */ 
  import re
  import phonenumbers
  from rest_framework import serializers
  from phonenumbers import carrier
  from validate_email import validate_email
  
  
  class basicSerializer(serializers.Serializer):
      emailplus = serializers.EmailField()
      country = serializers.CharField(max_length=2)
      phone_number = serializers.CharField(max_length=100)
  
      def validate_emailplus(self):
          email = self.validated_data.get("email")
          if not validate_email(email, check_mx=True, verify=True):
              raise serializers.ValidationError("Invalid email")
          return email
  
  /* views.py */ 
  from django.shortcuts import render
  from django.http import HttpResponse
  from django.shortcuts import get_object_or_404
  from rest_framework.views import APIView
  from rest_framework.response import Response
  from rest_framework import status
  from .models import basic
  from .serializers import basicSerializer
  
  
  class basicList(APIView):
  
      def get(self, request):
          basic1 = basic.objects.all()
          serializer = basicSerializer(basic1, many=True)
          return Response(serializer.data)
  
      def post(self):
          pass
  </code></pre>
  
  <p>As you can see I am not using models.py anymore and serializers.py as some sort of model with the given email and phone fields. In order for my function to work (which is not at the moment), it needs to use get() method from the entered data and do validate_email to know if the email exists. Please tell me what changes should be made, i do not know if the problem is with views.py which still uses models.py or if i should register the serializer as a model?</p>