【发布时间】:2018-06-28 11:19:21
【问题描述】:
我让 jquery 向 api 端点发送一个请求。代码如下:
$.get("http://localhost:5000/api/update/"+ elm2, function(data){});
端点定义如下:
@app.route('/api/update/<id>', methods=['GET'])
def check_new_entries(id):
result = Trades.query.filter_by(id=id).first_or_404()
new_entries = Trades.query.filter(Trades.time_recorded > result.time_recorded).all()
查询的表是:
class Trades(db.Model):
id = db.Column(db.String,default=lambda: str(uuid4().hex), primary_key=True)
amount = db.Column(db.Integer, unique=False)
time_recorded = db.Column(db.DateTime, unique=False)
问题: Jquery 成功发送了正确的请求,变量类型为字符串,但是在执行第一个查询时,它无法返回任何内容。 我在另一个应用程序中有一个类似的端点,它工作正常。为什么这是一个例外?可能缺少什么?我确信我正在查询的记录在数据库中,所以它应该返回它。
【问题讨论】:
标签: python jquery flask sqlalchemy flask-sqlalchemy