forked from drjkuria/head-first-python-2ed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_webapp.py
More file actions
38 lines (29 loc) · 728 Bytes
/
simple_webapp.py
File metadata and controls
38 lines (29 loc) · 728 Bytes
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
from flask import Flask, session
from checker import check_logged_in
app = Flask(__name__)
@app.route('/')
def hello() -> str:
return 'Hello from the simple webapp.'
@app.route('/page1')
@check_logged_in
def page1() -> str:
return 'This is page 1.'
@app.route('/page2')
@check_logged_in
def page2() -> str:
return 'This is page 2.'
@app.route('/page3')
@check_logged_in
def page3() -> str:
return 'This is page 3.'
@app.route('/login')
def do_login() -> str:
session['logged_in'] = True
return 'You are now logged in.'
@app.route('/logout')
def do_logout() -> str:
session.pop('logged_in')
return 'You are now logged out.'
app.secret_key = 'YouWillNeverGuess...'
if __name__ == '__main__':
app.run(debug=True)