forked from eesong/flask-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flaskblog.py
50 lines (38 loc) · 1.19 KB
/
flaskblog.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
from flask import Flask, render_template, url_for, flash, redirect
from forms import RegistrationForm, LoginForm
import datetime
app = Flask(__name__)
app.config['SECRET_KEY'] = '432798b5b6902e2bf5e1f02f993d824c'
posts = [{
'_id': 0,
'name': 'Bob',
'dob': datetime.datetime(1996, 11, 12, 11, 14),
'email': '[email protected]',
'status': 0
}, {
'_id': 1,
'name': 'Mason',
'dob': datetime.datetime(1996, 11, 12, 11, 14),
'email': '[email protected]',
'status': 1
}]
@app.route('/') #'/' is root page
@app.route('/home')
def home():
return render_template('home.html', posts=posts, title='home')
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.validate_on_submit():
flash(f'Account created for {form.username.data}!', 'success')
return redirect(url_for('home'))
return render_template('register.html', title='Register', form=form)
@app.route('/login')
def login():
form = LoginForm()
return render_template('login.html', title='Login', form=form)
@app.route('/about')
def about():
return render_template('about.html', title='about')
if __name__ == '__main__':
app.run(debug=True)