Flask Pedantic

Check code examples for Pedantic For Flask.

This article will be updated with examples.

Data List Check

Check Model:

class OperationsUpdateModel(basemodel):
id: int
confirmed: bool

How to check the data validation in the API and send an error:

@operations_bp.route(‘/update-operations/’, methods=[‘PATCH’])
@login_required
def update_operations_route():
try:
data = request.get_json()
try:
list_ = parse_obj_as(List[OperationsUpdateModel], data)
except Exception:
return {“error”: “Must be a list {id: int, confirmed: bool}”}, 400

return jsonify(‘ok’)
except Exception as e:
logger.error({e}, exc_info=True)

The site has no goal of self-sustaining, so there are no ads on the site. But if the information was useful to you, you can like the page, leave a comment, or send me a gift for a cup of coffee.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *