Skip to content

Instantly share code, notes, and snippets.

@sarojbelbase
Created December 22, 2020 16:00
Show Gist options
  • Save sarojbelbase/ef9dacbf80321211d71be7730c85b042 to your computer and use it in GitHub Desktop.
Save sarojbelbase/ef9dacbf80321211d71be7730c85b042 to your computer and use it in GitHub Desktop.
flask dictionary without marshmallow
from flask import jsonify
@app.route('/user_json')
def get_json():
user = User.query.filter_by(username='testme').first()
# Using the user object (without __dict__) will generate a runtime error
# TypeError: 'user' is not JSON serializable
return jsonify( user.__dict__ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment