Python 如何为其他app.routes引用Flask中的变量

Python 如何为其他app.routes引用Flask中的变量,python,matplotlib,flask,Python,Matplotlib,Flask,我是一名学生,正在学习如何使用flask,并计划将其与Matplotlib(graph maker库)集成。我已经从用户那里得到了输入,并将它们存储为变量。但是,在以后的代码中不能调用这些变量 这是我的烧瓶代码: @app.route('/', methods = ['POST','GET']) def upload_file(): global title, x_axis, y_axis if request.method == 'POST': f = req

我是一名学生,正在学习如何使用flask,并计划将其与Matplotlib(graph maker库)集成。我已经从用户那里得到了输入,并将它们存储为变量。但是,在以后的代码中不能调用这些变量

这是我的烧瓶代码:

 @app.route('/', methods = ['POST','GET'])
def upload_file():
    global title, x_axis, y_axis
    if request.method == 'POST':
        f = request.files['file']
        if True == allowed_file(f.filename):
            f.save(f.filename)
            print(f)

    if request.method == 'POST':
        if request.method == 'POST':
            reqform = request.form
            #
            title = reqform['title']
            x_axis = reqform['x_axis']
            y_axis = reqform['y_axis']
            #
            print(title, x_axis, y_axis)

    return render_template('uploaded.html') #, title = title, form = reqform, f = f.filename )
我想在另一个@app.route中调用变量,如
title
x\u轴
y\u轴
,以生成一个图形


我不确定我是否足够具体,但是,任何帮助都将不胜感激。谢谢

在路由器之间存储和访问数据有几种方法。实现这一点的一种方法是使用烧瓶:

 @app.route('/', methods = ['POST','GET'])
def upload_file():
    global title, x_axis, y_axis
    if request.method == 'POST':
        f = request.files['file']
        if True == allowed_file(f.filename):
            f.save(f.filename)
            print(f)

    if request.method == 'POST':
        if request.method == 'POST':
            reqform = request.form
            # assign in session variable

            session['title'] = reqform['title']
            session['x_axis'] = reqform['x_axis']
            session['y_axis'] = reqform['y_axis']

    return render_template('uploaded.html')

@app.route('/another_endpoint', methods = ['POST','GET'])
    def another_endpoint():
       title = session.get('title', None)
       x_axis = session.get('x_axis', None)
       y_axis = session.get('y_axis', None)
       # do something...