Flask 如何组合和匹配烧瓶中的两个表

Flask 如何组合和匹配烧瓶中的两个表,flask,sqlalchemy,flask-sqlalchemy,flask-restful,flask-login,Flask,Sqlalchemy,Flask Sqlalchemy,Flask Restful,Flask Login,该id与发布的id相关联。当我输入id(/postComments/id)时,如何获取该id的联系信息和评论信息? 我得到一个内部错误 类帖子(db.Model): __tablename=“posts” id=db.Column(db.Integer,主键=True) name=db.Column(db.String(100)) postName=db.Column(db.String(100)) postDescription=db.Column(db.String(500)) postLi

该id与发布的id相关联。当我输入id(/postComments/id)时,如何获取该id的联系信息和评论信息? 我得到一个内部错误

类帖子(db.Model):
__tablename=“posts”
id=db.Column(db.Integer,主键=True)
name=db.Column(db.String(100))
postName=db.Column(db.String(100))
postDescription=db.Column(db.String(500))
postLike=db.Column(db.Integer)
类后命令(数据库模型):
__tablename_u=“postComment”
id=db.Column(db.Integer,主键=True)
postID=db.Column(db.Integer)
senderName=db.Column(db.String(20))
commentPost=db.Column(db.String(300))
@app.route('/postComments/',方法=['GET'])
def get_comment_post(id):
userList=posts.query\
.join(postComment,posts.id==postComment.posted)\
.add_列(posts.id、posts.name、posts.postsdescription、postComment.commentPost、postComment.senderName)\
.filter(posts.id==id)
修改模型(并执行迁移)以允许外键引用:

类后指令(db.Model):
__tablename_u=“postComment”
id=db.Column(db.Integer,主键=True)
postID=db.Column(db.Integer,db.ForeignKey(“posts.id”))#修改模型(并执行迁移)以允许外键引用:

类后指令(db.Model):
__tablename_u=“postComment”
id=db.Column(db.Integer,主键=True)

postID=db.Column(db.Integer,db.ForeignKey(“posts.id”))#那里的数据转换有问题。我有评论信息(发件人、评论…)。我正在尝试获取这些评论以及该评论所属的帖子,但失败了:(尝试打印(my_post.\uu dict_uuu)
,你会得到什么?@BahadırSeyfimy_comment=postComment.get(id)AttributeError:type对象“postComment”没有属性“get”127.0.0.1---[24/Dec/2020 12:58:59]“get/postComments/2 HTTP/1.1”500-如果你读了这篇文章,可能会更容易理解:我的错!我将其更新为
postComment.query.get(id)
My_post=postComment.post AttributeError:type对象“postComment”没有属性“post”:(我不明白我在那里的数据转换有问题。我有注释信息(发件人,评论…)。我正在尝试获取这些评论以及该评论所属的帖子,但失败了:(当尝试打印(我的帖子)时,你会得到什么?@BahadırSeyfimy_comment=postComment.get(id)AttributeError:type对象“postComment”没有属性“get”127.0.0.1---[24/Dec/2020 12:58:59]“GET/postComments/2 HTTP/1.1”500-如果你读了这篇文章,可能会更容易理解:我的错!我将它更新为
postComment.query.GET(id)
My\u post=postComment.post AttributeError:type对象“postComment”没有属性“post”:(我不明白
class posts(db.Model):
    __tablename__ = "posts"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    postName = db.Column(db.String(100))
    postDescription = db.Column(db.String(500))
    postLike = db.Column(db.Integer)

class postComment(db.Model):
    __tablename__ = "postComment"
    id = db.Column(db.Integer, primary_key=True)
    postID = db.Column(db.Integer)
    senderName = db.Column(db.String(20))
    commentPost = db.Column(db.String(300))



@app.route('/postComments/<id>',methods=['GET'])
def get_comment_post(id):
    userList = posts.query\
    .join(postComment, posts.id == postComment.postID)\
    .add_columns(posts.id, posts.name, posts.postDescription, postComment.commentPost, postComment.senderName)\
    .filter(posts.id == id)