-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (28 loc) · 983 Bytes
/
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
from flask import Flask, render_template, request, redirect
from flask_sqlalchemy import SQLAlchemy
import datetime
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Messageboard(db.Model):
__tablename__ = 'messages'
id = db.Column(db.Integer, primary_key=True)
message_text = db.Column(db.Text())
timestamp = db.Column(db.DateTime)
def __init__(self, message_text, timestamp):
self.message_text = message_text
self.timestamp = timestamp
db.create_all()
db.session.commit()
@app.route("/")
def home():
new_message = request.args.get('msg')
if new_message:
timestamp = datetime.datetime.now()
data = Messageboard(new_message,timestamp)
db.session.add(data)
db.session.commit()
messages = Messageboard.query.all()
return render_template('home.html', messages=messages)