zkt21/z1/web/app.py
2021-04-04 02:17:49 +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()