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

PREVIOUS NEXT
Code Example
Python :: backtracking python 
Python :: json decode py 
Python :: change marker border color plotly 
Python :: ppcm python 
Python :: python read file into variable 
Python :: kruskal python implementation 
Python :: tokenizer in keras 
Python :: get_dummies 
Python :: django migrate model 
Python :: django include 
Python :: Convert two lists into a dictionary in python 
Python :: adding roles discord py 
Python :: end python print with space 
Python :: split a string into N equal parts. 
Python :: read value from entry tkinter 
Python :: dataframe in python 
Python :: how to write pretty xml to a file python 
Python :: set allowed methods flask 
Python :: how print 2 decimal in python 
Python :: python slice notation 
Python :: list comprehension 
Python :: how to for loop for amount in list python 
Python :: pandas data frame to list 
Python :: python integer to string 
Python :: python get the app path 
Python :: find max value in list python 
Python :: how to create an entry box on tkinter python 
Python :: print A to z vy using loop in python 
Python :: roblox api python 
Python :: python alphabetical order 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =