I am playing with Flask framework and I have a form where I input a value into a text box. The submit button fetches json object from an API endpoint and creates a file with the name of the value. Which is then stored back in the server as a text file. (one of flask's directories).
I want to perform a validation whenever a user enters the value on to the form -- check if the file with the same name exists. If it exits, alert the user that the file exits and the user could cancel to abort fetching the API again 'or' refetch the API to refresh the content.
With python I can perform the validation by doing
"os.path.exists('mydirectory/myfile.txt')"
Which will return me a true or a false.
How do I propogate it back to the flask page as an alert to the user? Can someone give me pointers as to should I be using javascript on the client side? I dont want to re-render the page with flask, I want the user to stay on the same page and just have an alert pop up with appropriate action.