2016-11-19 47 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模板。 –

相關問題