正在运行routes.py
@app.route('/articles', methods=['GET', 'POST'])
def articles():
upload()
return render_template('articles.html')
这个保存图像并处理其信息的功能
def upload():
if request.method == 'POST':
# Save the file to static/uploads
label = "some string from process above"
probability = "another string"
return None
return None
如何在渲染模板时使用变量标签和概率?有些人使用接近的东西
return render_template('articles.html', label=label, probability=probability)
这样做是为了使用js引用变量。但是,如果该变量是在upload((中计算的,我该如何引用它呢?是否需要全局变量?
您可以从函数中返回这些变量。
您必须解压缩从upload
函数发送的变量。
首先,您必须从upload
返回它们,然后拆包将其发送到render_template
。
@app.route('/articles', methods=['GET', 'POST'])
def articles():
label, probability = upload()
return render_template('articles.html', label=label, probability=probability)
def upload():
if request.method == 'POST':
# Save the file to static/uploads
label = "some string from process above"
probability = "another string"
return (label, probability)
return (None, None)