flask一个delete键删除一条评论


后台从数据库查询出可能要删除的评论后,前端/后端如何控制一个delete键只删除其对应的评论,而不影响其他评论?(使用db.session.delete(),db.session.commit())
后台查询评论部分代码:


 comments = Comment.query.all()
lists=[]
if form.validate_on_submit():
        keywords = form.content.data
        for comment in comments:
            if keywords in comment.body:
                #comp   = form.completed.data
                comment_body = comment.body
                com = Comment.query.filter_by(body=comment_body).first()
                postid = com.post_id
                posts = Post.query.filter_by(post_id=postid).first()
                titles = posts.title
                lists.append(dict(comment_body = comment.body, postid = com.post_id, titles = posts.title))
        return render_template('comment_search.htm',form=form,commentss=lists)

python-flask

JohnLi2 10 years, 4 months ago

Your Answer