Whenever you create web forms, it's a good idea to validate the fields before processing them. It's an especially good idea when you're getting ready to implement file upload. Anyway, here it is with the Python micro framework of Flask with the wtforms and Flask_WTF libraries.