Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2019 13:36
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
flask app using sessions and the flask session extension
from flask import Flask, redirect, render_template, request, session
from flask_session import Session
# Configure app
app = Flask(__name__)
# Configure sessions
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
# Items for sale
ITEMS = ["foo", "bar", "baz"]
def index():
return render_template("index.html")
@app.route("/update", methods=["POST"])
def update():
for item in request.form:
session[item] = int(request.form.get(item))
return redirect("/cart")
def cart():
return render_template("cart.html", cart=session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment