Skip to content

Instantly share code, notes, and snippets.

@arajkumar
Created May 19, 2020 05:46
Show Gist options
  • Save arajkumar/c7e5da7e35c9011f047a322c0c91bfe2 to your computer and use it in GitHub Desktop.
Save arajkumar/c7e5da7e35c9011f047a322c0c91bfe2 to your computer and use it in GitHub Desktop.
Pydantic and Flask formdata validation
from flask import Flask
from flask import request
from werkzeug.datastructures import FileStorage
from pydantic import BaseModel
app = Flask(__name__)
class FormData(BaseModel):
file_path: str
ecosystem: str
manifest: FileStorage
class Config:
arbitrary_types_allowed = True
@app.route('/hello', methods=['POST'])
def helloIndex():
print(FormData(**request.form, **request.files))
return 'Hello World from Python Flask!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment