Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将烧瓶视图值传递给要使用的其余代码_Python_Flask - Fatal编程技术网

Python 将烧瓶视图值传递给要使用的其余代码

Python 将烧瓶视图值传递给要使用的其余代码,python,flask,Python,Flask,这就是我希望能够使用view函数中的值所做的事情 vaa = 1 @app.route('/', methods=['POST', 'GET']) def index(): if request.method == 'POST': global vaa vaa = request.form.get('age') return render_template('index.html', vaa ) 我想将一个值从视图向下传递到代码的其余部分,

这就是我希望能够使用view函数中的值所做的事情

vaa = 1
@app.route('/', methods=['POST', 'GET'])
def index():

    if request.method == 'POST':
        global vaa
        vaa = request.form.get('age')


    return render_template('index.html', vaa )

我想将一个值从视图向下传递到代码的其余部分,而不是传递到另一个视图函数,使用全局变量“不工作”,请提供任何帮助。

也许您可以将该值存储在会话中

myage = vaa

def fun(vaa):

    return vaa


if __name__ == "__main__":
    app.run(debug=True)
from flask import Flask , session, render_template  
app = Flask(__name__)  
app.secret_key = "abc"  
 
@app.route('/', methods=['POST', 'GET'])
def index():
    if request.method == 'POST':
        vaa = request.form.get('age')
        session["age"] = vaa
    else :
        return render_template('index.html', age = vaa )


@app.route('/age', methods=['POST', 'GET'])
def get_age():
    return render_template('age.html', user_age = session['age'])