Assigning same session ID for returning users with Python Flask app
<p>I have a simple Flask webapp that does not require users to log in. However, I would like to assign an identifier to a user so that same users can be identified without user's log-in id. Is there a way to achieve this? </p>

<p>You can put information in the session and recover it in server-side using flask     session:</p>

<pre><code>from flask import Flask, session, redirect, url_for, request

app = Flask(__name__)   

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        session['cookie-parameter'] = request.form['data-from-form']
        return redirect(url_for('other_endpoint'))
    return redirect(url_for('other_endpoint'))

@app.route('/other-url')
def other_endpoint():
    session.pop('cookie-parameter', None)
    return redirect(url_for('index'))

# Don't forget to add the secret key
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
</code></pre>

<p>Hope it helps!</p>

python flask