0
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 )

This are the things i want to be able to do with the values from the view function.

myage = vaa

def fun(vaa):

    return vaa


if __name__ == "__main__":
    app.run(debug=True)

I want to pass a value from the view down to the rest of the code, not to another view function, using global variable don't work, any help, please.

Azucode
  • 127
  • 1
  • 7

1 Answers1

0

Maybe you could store the value in sessions ?

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'])
Vishnu Joshi
  • 333
  • 1
  • 9