-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (34 loc) · 1.14 KB
/
app.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, request, jsonify
from database import load_comments_from_db, add_comments_to_db, add_contact_to_db
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/posts', methods=['get', 'post'])
def posts():
comments = load_comments_from_db()
data= request.form
return render_template('first_blog.html', data=data, comments=comments)
@app.route('/api/posts')
def list_comments():
comments = load_comments_from_db()
return jsonify(comments)
@app.route('/posts/new_comment', methods=['post'])
def comment():
data = request.form
add_comments_to_db(data)
comments = load_comments_from_db()
return render_template('first_blog.html', data=data, comments=comments)
@app.route('/contact/new', methods=['post'])
def new_contact():
data = request.form
add_contact_to_db(data)
return render_template('contact.html', data=data)
if __name__ == "__main__":
app.run(debug=True)