mardi 6 octobre 2020

Showing number of answers functionality does not work

I have this forum site where users can ask questions and receive answers, abd I tried to also show the numbers of answers a question has received but the code does not work so I need help

This is the html where I want to show it:

<span>
      Answers
</span>

This is the code used in the view:

    @app.route('/')
    @app.route('/home')
    def home():
        page = request.args.get('page', 1, type=int)
        questions = Question.query.order_by(
           Question.date_added.desc()).paginate(page=page, per_page=5)
    return render_template('blog.html', questions=questions)

This is the database code:

class Question(db.Model):
   id = db.Column(db.Integer, primary_key=True)
   title = db.Column(db.String(500), nullable=False)
   content = db.Column(db.Text, nullable=False)
   tag_1 = db.Column(db.String(50), nullable=False)
   tag_2 = db.Column(db.String(50), nullable=False)
   date_added = db.Column(db.DateTime, nullable=False,
                       default=datetime.utcnow)
   user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

   answers = db.relationship('Answer', backref='question', lazy=True)

   def __repr__(self):
      return self.title



Aucun commentaire:

Enregistrer un commentaire