📅  最后修改于: 2022-03-11 14:46:44.048000             🧑  作者: Mango
@app.route('/', methods = ['GET', 'POST'])
@app.route('/index', methods = ['GET', 'POST'])
@login_required
def index():
form = PostForm()
if form.validate_on_submit():
post = Post(body = form.post.data, timestamp = datetime.utcnow(), author = g.user)
db.session.add(post)
db.session.commit()
flash('Your post is now live!')
return redirect(url_for('index'))
posts = g.user.followed_posts().all()
return render_template("index.html",
title = 'Home',
user = user,
posts = posts,
form = form)