我有一个flask应用程序,我需要将变量从一个函数传递给另一个函数。这里的要求是我需要将index()中的'skill'值传递给get_image(),有关如何实现的任何想法?
@app.route('/', methods=['POST'])
def index():
data = json.loads(request.get_data())
skill = data['conversation']['skill']
@app.route("/get-image/<image_name>")
def get_image(image_name):
if skill == 'getpositions':
# some code
答案 0 :(得分:2)
例如,您可以尝试使用flask sessions
:
from flask import Flask, session
...
@app.route('/', methods=['POST'])
def index():
data = json.loads(request.get_data())
skill = data['conversation']['skill']
session['skill'] = skill
@app.route("/get-image/<image_name>")
def get_image(image_name):
if session['skill'] == 'getpositions':
#some code