-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
38 lines (33 loc) · 1.21 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
from flask import Flask, render_template, request
from formLogic import CreateMessage, ListMessages
app = Flask(__name__,
template_folder="templates")
totalMessages = 0
allMessages = []
def addMessageCount(value):
global totalMessages
totalMessages += value
@app.route("/", methods=['GET', 'POST'])
def home():
"""Serve message form."""
sendMessageForm = CreateMessage()
msgBoardData = []
if request.method == 'POST':
thisMessage = CreateMessage(request.form)
if thisMessage.validate():
sentMessage = ListMessages(request.form)
allMessages.append(sentMessage)
addMessageCount(1)
msgBoardData = allMessages
else:
return render_template("main.html",
form=thisMessage,
count=totalMessages,
msgBoard=allMessages)
return render_template("main.html",
form=sendMessageForm,
count=totalMessages,
msgBoard=msgBoardData)
if __name__ == '__main__':
app.secret_key = 'notSoSecret'
app.run(debug = True)