2016-11-19 79 views

回答

1

您不能简单地返回列表,您必须返回Flask知道如何解释为HTTP响应的内容。这里有一个例子来自the docs

@app.route('/') 
def show_entries(): 
    db = get_db() 
    cur = db.execute('select title, text from entries order by id desc') 
    entries = cur.fetchall() 
    return render_template('show_entries.html', entries=entries) 

正是你应该返回取决于你的使用情况。如果您想要返回JSON响应,请考虑jsonify

+0

它适用于:'cursor.fetchone()',但我想获取所有标题不只是一个 –

+0

@FidelCastro你想要人类可读的东西显示给用户吗?如果是这样,请呈现HTML模板。 –

相关问题