-1

I ask a very similar question like this yesterday and was directed here. I took what was posted there (using a session) to take in a user input, update a second page with a data table. However, If I get to that second route through any other means, it resorts back to the default which is an empty data table. So I'm thinking that the variable is not being updated and saved or being rewritten. Code below

@app.route('/', methods=['GET','POST'])
def index():
    loadform = LoadDataForm()
    session['dataset'] = toy_data.get_empty_df()

    if loadform.validate_on_submit():
        dataset, headers = toy_data.get_dataset(int(loadform.selectToyData.data))
        session['dataset'] = dataset
        session.modified = True
        return render_template('DataTable.html',dataset=dataset)

    return render_template('LoadData.html',form=loadform)

@app.route('/DataTable', methods=['GET','POST'])
def index_data():
    dataset = session.get('dataset',None)

    return render_template('DataTable.html',dataset=dataset)
davidism
  • 121,510
  • 29
  • 395
  • 339
jon
  • 349
  • 3
  • 4
  • 20

1 Answers1

0

The data you are setting is added to the session. That’s why it’s not set in a different session.

gugi9000
  • 1
  • 1
  • Hi! Can you please be more elaborate with your answer. It looks like a comment to me. – Aniket Tiratkar Nov 12 '20 at 07:02
  • I figured it was something along those lines (I know almost nothing about sessions, was just recommended it) Could you possibly show how to set the data in the correct session? – jon Nov 12 '20 at 15:39