概述
class Answer(db.Model):
tablename = 'answer'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
content = db.Column(db.Text, nullable=False)
question_id = db.Column(db.Integer,db.ForeignKey('question.id'))
author_id = db.Column(db.Integer,db.ForeignKey('user.id'))
create_time = db.Column(db.DateTime,default=datetime.now)
question = db.relationship('Question',backref=db.backref('answers',order_by=id.desc()))
author = db.relationship('User',backref=db.backref('answers'))
@app.route('/add_awswer/',methods=['POST'])
def and_awser():
content = request.form.get('answer_content')
question_id = request.form.get('question_id')
answer = Answer(content=content)
userId = session['user_id']
user = User.query.filter(User.id == userId).first()
answer.author = user
question = Question.query.filter(Question.id == question_id).first()
answer.question = question
db.session.add(answer)
db.session.commit()
return redirect(url_for('detail',question_id = question_id))
本人菜鸟,我想在模板中获取 Answer 模型中总共有多少条数据
最后
以上就是飞快小刺猬为你收集整理的flask 读取mysql 表_flask 项目,想获取数据库中的某个表有多少条数据记录该如何实现...的全部内容,希望文章能够帮你解决flask 读取mysql 表_flask 项目,想获取数据库中的某个表有多少条数据记录该如何实现...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复