zkt21/sk1/web/app.py
2021-05-24 19:48:55 +02:00

31 lines
619 B
Python

# app.py
from flask import Flask
from flask import request, render_template
from flask_sqlalchemy import SQLAlchemy
from config import BaseConfig
app = Flask(__name__)
app.config.from_object(BaseConfig)
db = SQLAlchemy(app)
from models import *
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
text = request.form['text']
post = Post(text)
db.session.add(post)
db.session.commit()
posts = Post.query.order_by(Post.date_posted.desc()).all()
return render_template('index.html', posts=posts)
if __name__ == '__main__':
app.run()