简体   繁体   English

如何摆脱烧瓶博客中的帖子?

[英]How do I get rid of a post from a flask blog?

I made a blog and want to get rid of a blog post thought the front end. 我创建了一个博客,并希望摆脱以前端为主题的博客文章。 And I have some trouble with it and getting the error 我有一些麻烦,并得到错误

"sqlalchemy.orm.exc.UnmappedInstanceError: Class 'builtins.int' is not mapped"

I think that the view is messed up but i am not too sure. 我认为观点是混乱的,但我不太确定。 Would love any feedback, Thanks!! 希望得到任何反馈,谢谢!

home.html
<span class="pull-right"><a class="text-danger" href="{{ url_for('delete_post', posts_id=posts.id) }}">[delete]</a></span>

views
@app.route('/delete_post/<int:posts_id>/', methods=('GET', 'POST'))
def delete_post(posts_id):
    posts = Blogpost.query.filter_by(id=posts_id).first_or_404()
    db.session.delete(posts_id)
    db.session.commit()
    return redirect(url_for('home'))

models
class Blogpost(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(20))
date_posted = db.Column(db.DateTime)
content = db.Column(db.Text)

您需要将帖子查询(而不是ID)传递给delete方法。

db.session.delete(posts)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM