1@app.route('/')
2def index():
3 resp = make_response(render_template(...))
4 resp.set_cookie('somecookiename', 'I am cookie')
5 return resp
6
7@app.route('/get-cookie/')
8def get_cookie():
9 username = request.cookies.get('somecookiename')
1from flask import Flask, render_template, make_response, request
2id_list = [0]
3
4@app.route('/')
5def setcookie():
6 resp = make_response(render_template('index.html'))
7 resp.set_cookie('id', id_list[len(id_list) - 1] + 1)
8 id_list.append(id_list[len(id_list) - 1] + 1)
9 return resp
10
11@app.route('/show_id')
12def show_id():
13 return f'<h1>welcome {request.cookies.get("id")} </h1>'
14