Skip to content

Instantly share code, notes, and snippets.

Embed
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"
Session(app)
# Items for sale
ITEMS = ["foo", "bar", "baz"]
@app.route("/")
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")
@app.route("/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