所以基本上我有两个功能
@app.route('/index', methods=['GET'])
def do_stuff1():
*LOGIC*
return (render_template('index.html', data=data))
和
@app.route('/index', methods=['GET'])
def do_stuff2():
*LOGIC*
return (render_template('index.html', moreData=moreData))
我如何将数据从第二个函数传递到同一个模板,因为它没有像我在那里指定的那样工作。我只得到第一个函数数据。
编辑:我应该指定我想在同一 route 使用数据。
最佳答案
您的第二个函数不必是“ View ”,而只是一个普通的 Python 函数。除非我遗漏了什么...
@app.route('/index', methods=['GET'])
def do_stuff1():
*LOGIC*
moreData = do_stuff2()
return render_template('index.html', data=data, moreData=moreData)
关于python - Flask - 将数据从不同的函数传递到同一个模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35988664/