Answers for "flask set cookie"

1

flask set cookie

@app.route('/')
def index():
    resp = make_response(render_template(...))
    resp.set_cookie('somecookiename', 'I am cookie')
    return resp 

@app.route('/get-cookie/')
def get_cookie():
    username = request.cookies.get('somecookiename')
Posted by: Guest on December-19-2020
2

flask set cookie

response = make_response('Any thing...')
  resp.set_cookie('name', 'value')
Posted by: Guest on December-03-2020
0

flask cookckies

from flask import Flask, render_template, make_response, request
id_list = [0]

@app.route('/')
def setcookie():
  resp = make_response(render_template('index.html'))
  resp.set_cookie('id', id_list[len(id_list) - 1] + 1)
  id_list.append(id_list[len(id_list) - 1] + 1)
  return resp

@app.route('/show_id')
def show_id():
  return f'<h1>welcome {request.cookies.get("id")} </h1>'
Posted by: Guest on October-08-2020

Python Answers by Framework

Browse Popular Code Answers by Language