Python Flask - how to remember anonymous users via cookie/session? Python Flask - how to remember anonymous users via cookie/session? flask flask

Python Flask - how to remember anonymous users via cookie/session?


There is no perfect solution to your problem because you will not be able to identify a user if they are anonymous.

The most practical is probably to use sessions and save that they completed the survey in a session variable. But if they clear their cookies they will be able to enter the site again.

Example implementation:

from flask import session, app@app.before_requestdef make_session_permanent():    session.permanent = True

In your survey form view:

if not "already_participated" in session:    ... Display form

And then in your submit view:

session["already_participated"] = True