-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (39 loc) · 1.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from flask import Flask, redirect, url_for, render_template, request, session, flash
from datetime import timedelta
app = Flask(__name__)
app.secret_key = "hello"
app.permanent_session_lifetime = timedelta(days=5)
@app.route("/")
def home():
return render_template("home.html")
@app.route("/login", methods=["POST", "GET"])
def login():
if request.method == "POST":
session.permanent = True
user = request.form["nm"]
session["user"] = user
flash("Login Successful!")
return redirect(url_for("user"))
else:
if "user" in session:
flash("Already logged in!")
return redirect(url_for("user"))
return render_template("login.html")
@app.route("/user")
def user():
if "user" in session:
user = session["user"]
return render_template("user.html", user=user)
else:
flash("You are not logged in!")
return redirect(url_for("login"))
@app.route("/logout")
def logout():
flash("You have been logged out!", "info")
session.pop("user", None)
return redirect(url_for("login"))
if __name__ == "__main__":
app.run(debug=True)
# @app.route("/<name>")
#def home(name):
# return render_template("home.html", content=name)