I can't figure out how to return the information from my database when using GET method because I keep getting errors in my return statements. I keep getting errors like object not subscriptable or stuff to do with dicts.
I tried.
return jsonify({'developers': User.query.all()})
I got the error TypeError: <main.User object at 0x038FC9D0> is not JSON serializable
When i try
return json.dumps(tuple[User.query.all()])
I get the error. TypeError: 'type' object is not subscriptable
from flask import Flask, jsonify,json
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_pyfile('Config.py')
db = SQLAlchemy(app)
class User(db.Model):
User_ID = db.Column(db.Integer, primary_key = True)
firstName = db.Column(db.String(20))
lastName = db.Column(db.String(20))
def __init__(self,firstName, lastName):
self.firstName = firstName
self.lastName = lastName
db.create_all()
@app.route('/', methods = ['GET'])
def index():
return json.dumps(tuple[User.query.all()])
if __name__ == '__main__':
app.run()
tuple(User.query.all())? Use of(...)instead of[...]for type-casting totuple. Also provide the complete stack-trace