Sessions do not persist between routes in flask on replit

66 views Asked by At

My sessions do not persist between routes on replit. I create a sesssion and then redirect to another route. The session is then cleared for some reason. It will still have all the config, but all data that was entered into the session is empty. This is an example code of the issue. If the sessions did persist it should just display a webpage that contains 1, but it does not. It only returns a webpage for "Code does not work":

from flask import Flask, render_template, session, redirect, url_for
app = Flask(__name__)
app.secret_key = 's3cr3t'
app.config['SESSION_TYPE'] = 'filesystem'

@app.route('/')
def home():
  x = session.get('x', None) 
  if not x:
    session['x'] = 1
return redirect(url_for('foo'))

@app.route('/foo')
def foo():
  x = session.get('x', None)
  print(x)
  if x:
    return x
  else:
    return 'Code does not work'

if __name__ == '__main__':
  app.run(host='0.0.0.0')

At first, I thought it was because I was using a GET method instead of a POST method in the form (Which is what I'm putting into the session) but changing that didn't work. I'm not even sure why this is happening it seems to work on other replits, and my code is the same on both.

0

There are 0 answers