forked from tecladocode/testing-python-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (30 loc) · 940 Bytes
/
Copy pathapp.py
File metadata and controls
46 lines (30 loc) · 940 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
39
40
41
42
43
44
45
46
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
posts = []
@app.route('/')
def homepage():
return render_template('home.html')
@app.route('/blog')
def blog_page():
return render_template('blog.html', posts=posts)
@app.route('/post', methods=['GET', 'POST'])
def add_post():
if request.method == 'POST':
title = request.form['title']
content = request.form['content']
global posts
posts.append({
'title': title,
'content': content
})
return redirect(url_for('blog_page'))
return render_template('new_post.html')
@app.route('/post/<string:title>')
def see_post(title):
global posts
for post in posts:
if post['title'] == title:
return render_template('post.html', post=post)
return render_template('post.html', post=None)
if __name__ == '__main__':
app.run()