flask显示数据库已有内容
main.py
1# coding: utf-8
from sqlalchemy import CheckConstraint, Column, Integer, Text
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from flask import Flask,url_for,redirect,render_template,request
import os,sys
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db = SQLAlchemy(app)
class Teacher(db.Model):
__tablename__ = 'Teachers'
Id = db.Column(db.Integer, primary_key=True)
Name = db.Column(db.Text)
Age = db.Column(db.Integer)
Country = db.Column(db.Text)
def __init__(self,Name,Age,Country):
self.Name = Name
self.Age = Age
self.Country = Country
@app.route('/', methods=['GET'])
def home():
article = Teacher.query.all()
return render_template('show_article.html',article=article)
if __name__ =='__main__':
app.run(port=8000)
show_article.html
| Name | Age | Country |
|---|---|---|
| {{article.Name}} | {{article.Age}} | {{article.Country}} |