Flask 编辑修改内容 功能

Posted 青青子衿_MI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 

以上是关于Flask 编辑修改内容 功能的主要内容,如果未能解决你的问题,请参考以下文章