I have assigned a pandas dataframe globally
df = pd.read_csv('file.csv')
I have a Flask app with a submit route that's triggered once user makes a POST request from the browser.
@app.route('/submit')
def sub():
// do some filtering in df
return redirect(url_for('recommend', uid=1))
I would like sub()
to pass df to /recommend
.
@app.route('/recommend/<int uid>')
def rec(uid):
// make recommendations based on df
return df.to_html()
The problem is, how do I pass it? I've tried passing it in the URL query
@app.route('/submit')
def sub():
// do some filtering in df
return redirect(url_for('recommend', uid=1, df=df))
@app.route('/recommend/<int uid>/<df>')
def rec(uid,df):
// make recommendations based on df
return df.to_html()
But this turns df
to a string. I thought the path of least resistance would be to just make df
global, but any local manipulations to df
inside sub()
are not getting picked up globally.