I deployed my Flask app on Google App Engine (GAE). I've noticed that the forms on my app, like the search bar, login, and signup forms, sometimes work on browsers like Google Chrome, but then they stop functioning after a period, and they might start working again after a while. This behavior persists across different browsers like Firefox and Microsoft Edge.
When I say they're not working, I mean that when I submit a form, the page just refreshes without performing the expected actions. I've checked the logs on Google App Engine and looked for potential errors on Google Dev, but I haven't found any relevant error messages or explanations.
Has anyone else encountered a similar issue with a Flask app on Google App Engine? Any insights or solutions would be much appreciated.
* I'm not sure if this behavior is related to headers or not! But if yes, then how can I set that configuration (probably in app.yaml) ?
Update on the issue with WTForms in Flask and CSRF tokens: Upon further investigation, I've observed that when I submit forms on the deployed version of my application, the CSRF token doesn't appear to be getting stored in the session cookies. Consequently, the line of code form.validate_on_submit() is not functioning as expected. As a consequence, the form validation is failing, leading to the page being rendered again without redirecting.
This is the code for the login part:
@App.route('/login', methods=["GET", "POST"])
def login():
""" Handle user login. """
form = LoginForm()
if form.validate_on_submit():
user = User.authenticate(form.username.data,
form.password.data)
if user:
do_login(user)
welcome_msg = f"Hi {user.username}! Hope you find perfect movies to watch tonight."
return redirect(url_for("show_homepage", welcome_msg=welcome_msg ))
flash("Invalid credentials.", 'danger')
print(form.errors)
return render_template('users/login.html', form=form)