I am trying to return a json data after query from my database using Flask Alchemy, and Flask Marshmallow
However, my code somehow always returns empty JSON data.
Here's my code :
My View :
@app.route('/customer/', methods=['GET'])
def get_customer():
customers = models.Customer.query.all()
#c = models.Customer.query.get(1) # Get Customer with an ID of 1
customers_schema = CustomerSchema()
print customers_schema.dump(customers).data
payload = customers_schema.dump(customers).data
resp = Response(response=payload, status=200, mimetype="application/json")
return(resp)
My Models :
class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True)
nickname = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
address = db.relationship('Address', backref='customer', lazy='dynamic')
def __repr__(self):
return '<Customer %r>' % (self.nickname)
My Schema :
class CustomerSchema(ma.ModelSchema):
class Meta:
model = Customer
This is the result as seen from the console :
* Debugger is active!
* Debugger pin code: 817-774-044
{}
127.0.0.1 - - [12/Nov/2016 09:37:59] "GET /customer/ HTTP/1.1" 200 -
{}
127.0.0.1 - - [12/Nov/2016 09:41:27] "GET /customer/ HTTP/1.1" 200 -
Is there anything that i miss ? Can anyone help ?