I have a function that I want to call each time a web visitor hits '/'(home page). I would also line to use the results of that function in other functions. Any recommendations on how to do this?
@app.route('/')
def home():
store = index_generator() #This is the local variable I would like to use
return render_template('home.html')
@app.route('/home_city',methods = ['POST'])
def home_city():
CITY=request.form['city']
request_yelp(DEFAULT_LOCATION=CITY,data_store=store) """I would like to use the results here"""
return render_template('bank.html')
Flask – Variable Rules. This variable part is marked as <variable-name>. It is passed as a keyword argument to the function with which the rule is associated. In the following example, the rule parameter of route () decorator contains <name> variable part attached to URL ‘/hello’. Hence, if the...
Flask – Variable Rules. It is possible to build a URL dynamically, by adding variable parts to the rule parameter. This variable part is marked as <variable-name>. It is passed as a keyword argument to the function with which the rule is associated.
Im a student learning how to use flask and planning to integrate it with Matplotlib ( The graph maker library). I have got inputs from the user and stored them as variables. However, the variables are not callable upon in later code. This is my code for flask:
Using abort function to exit from the code loop, in conjunction to redirect. Here the code refers to a set of codes that will generate some error, as applicable, and stop any further execution of the application. How does redirect Function Works in Flask?
See the Flask session docs. You need to do some minor settings.
from flask import session
@app.route('/')
def home():
store = index_generator()
session['store'] = store
return render_template('home.html')
@app.route('/home_city',methods = ['POST'])
def home_city():
CITY=request.form['city']
store = session.get('store')
request_yelp(DEFAULT_LOCATION=CITY,data_store=store)
return render_template('bank.html')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With