Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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')
Comment

flask cookies

# https://cs50.harvard.edu/college/2020/fall/notes/9/

from flask import Flask, redirect, render_template, request, session
from flask_session import Session

app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)


@app.route("/")
def index():
    if not session.get("name"):
        return redirect("/login")
    return render_template("index.html")


@app.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        session["name"] = request.form.get("name")
        return redirect("/")
    return render_template("login.html")


@app.route("/logout")
def logout():
    session["name"] = None
    return redirect("/")
  
app.run(host='0.0.0.0', port=80)
Comment

flask set cookie

  response = make_response('Any thing...')
  resp.set_cookie('name', 'value')
Comment

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')
Comment

flask cookies

# https://cs50.harvard.edu/college/2020/fall/notes/9/

from flask import Flask, redirect, render_template, request, session
from flask_session import Session

app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)


@app.route("/")
def index():
    if not session.get("name"):
        return redirect("/login")
    return render_template("index.html")


@app.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        session["name"] = request.form.get("name")
        return redirect("/")
    return render_template("login.html")


@app.route("/logout")
def logout():
    session["name"] = None
    return redirect("/")
  
app.run(host='0.0.0.0', port=80)
Comment

flask set cookie

  response = make_response('Any thing...')
  resp.set_cookie('name', 'value')
Comment

PREVIOUS NEXT
Code Example
Python :: Comparison of two csv file and output with differences? 
Python :: python dictionary pop 
Python :: how to make timer in python 
Python :: np reshape 
Python :: for pyton 
Python :: selenium get h1 text python 
Python :: is vs == python 
Python :: np.tanh 
Python :: rename files with spaces in a folder python 
Python :: python datetime move forward one day 
Python :: request.build_absolute_uri django 
Python :: how to filter queryset with foreign key in django 
Python :: python opérateur ternaire 
Python :: jupyter change cell to text 
Python :: how to return a missing element in python 
Python :: Rectangle with python 
Python :: count number items in list python 
Python :: why to use self in python 
Python :: create excel file python 
Python :: terminal output redirect to a file 
Python :: python gzip a file 
Python :: decode multipart/form-data python lambda 
Python :: use proxy to connect smtp python 
Python :: discord py fetch message 
Python :: rename column by indexing 
Python :: power of array 
Python :: Class In Python With Instance Method 
Python :: python for in for in 
Python :: raw input example py 
Python :: How to develop a UDP echo client? 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =