diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-08-01 09:45:10 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-08-01 09:45:10 +0000 |
commit | 090a2ed3ce9d1ff69063d43359d2d79448d0e28d (patch) | |
tree | 26863c96309e1f87ac161dda5fb6f78632dc82f4 | |
parent | ea3d6a3d93123e7d8a19a7c0321f95116b962d1e (diff) |
Thu, Aug 1, 2024, 2:45 AM -07:00
-rw-r--r-- | wk9/lect/cookies/app.py | 6 | ||||
-rw-r--r-- | wk9/lect/cookies/templates/index.html | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/wk9/lect/cookies/app.py b/wk9/lect/cookies/app.py index bc7ab19..74b7964 100644 --- a/wk9/lect/cookies/app.py +++ b/wk9/lect/cookies/app.py @@ -1,4 +1,5 @@ from flask import Flask, render_template, request, session +from flask_session import Session app = Flask(__name__) @@ -8,11 +9,12 @@ Session(app) @app.route("/") def index(): - return render_template("index.html") + return render_template("index.html", name=session.get("name")) @app.route("/login") def login(): if request.method == "POST": - session + session["name"] = request.form.get("name") + return redirect("/") return render_template("login.html") diff --git a/wk9/lect/cookies/templates/index.html b/wk9/lect/cookies/templates/index.html index f902b58..3f08ec1 100644 --- a/wk9/lect/cookies/templates/index.html +++ b/wk9/lect/cookies/templates/index.html @@ -4,11 +4,11 @@ {% if name %} - You are logged in as {{ name }}. + You are logged in as {{ name }}. <a href="/logout">Log out</a>. {% else %} - You are not logged in. + You are not logged in. <a href="/login">Log in</a>. {% endif %} |