'connected to postgres but not able to populate data on UI

I am trying to retrieve data from postgreysql using flask. But when I am populating it, it is only showing blank in the table that I have created on my about.html page. I think my database connection is ok but somehow it is not getting passed in the code.

my about.html file

{% extends "base.html" %}
    {% block content %}
    <h1>Table Data</h1>    
        <table class="container">
          <thead>
            <tr>
              <th><h1>ID</h1></th>
              <th><h1>Name</h1></th>
              <th><h1>Salary</h1></th>
              <th><h1>Department ID</h1></th>
            </tr>
          </thead>
          <tbody>
              {% for row in receiveddata %}
            <tr>
              <td>{{row.Id}}</td>
              <td>{{row.Name}}</td>
              <td>{{row.Salary}}</td>
              <td>{{row.Dept_id}}</td>
            </tr>
            
            {% endfor %}
          </tbody>
        </table>
    {% endblock content %}

my python code

from datetime import datetime
from flask import Flask, render_template, url_for
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.secret_key = "Secret Key"

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:hema9868806346@localhost/Test'
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False

db=SQLAlchemy(app)

class employee(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(100))
    salary= db.Column(db.Integer)
    dept_id = db.Column(db.String(100))

    def __init__(self, id, name, salary, dept_id):
        self.Id = id
        self.Name = name
        self.Salary = salary
        self.Dept_id = dept_id

posts = [
    {
        'author': 'Hemant',
        'date_posted': datetime.now(),
        'title':'Blog 1',
        'content': 'My first Post',
    },
]

@app.route('/')
@app.route('/home')
def home():
    return render_template("home.html", posts=posts) 

@app.route('/about')
def about():

    all_data = employee.query.all()
    return render_template("about.html", receiveddata = all_data)

if __name__ == '__main__':
    app.run(debug=True)

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source