Flask 编辑修改内容 功能

@app.route('/edit/<id>', methods=['GET', 'POST'])
@login_required
def edit(id):
    content = Article.query.filter_by(id=id).first()     
    form = postForm(title=content.title, body=content.body)         #form里面存入默认值
    if form.validate_on_submit():
        post = Article()
        post.id = int(id)
        post.title = form.title.data
        post.body = form.body.data
        db.session.merge(post)
        db.session.commit()
        return redirect('/post/'+id)
    return render_template('write.html', form=form)

 

posted @ 2017-09-25 23:09  Mirgo  阅读(1449)  评论(0编辑  收藏  举报