'Django form validation based on custom function that calls api to validate form input value

I've been trying to look around for resources on how to do this, but no luck so far. Any direction would be appreciated!

I'm attempting to run a custom function on a Django form as validation. So, how it would work is:

  1. User submits form
  2. Within the validation, there is a function that calls an external API with the input value
  3. If the API returns a valid response, the form submission completes successfully
  4. If the API returns an error, the form validation is failed and a notification is returned to frontend with error.

Any direction on how this could be accomplished would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source