Use of Flask and echarts

init .py (initialization)

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import Config

app = Flask(name)

app.config.from_object(Config)

db = SQLAlchemy(app)

config.py (configuration class)

class Config(object):
SQLALCHEMY_DATABASE_URI ='mysql+pymysql://user:password@localhost:3306/db'
SQLALCHEMY_TRACK_MODIFICATIONS = True #Set
the changes in the database to be automatically submitted after each request
SQLALCHEMY_COMMIT_ON_TEARDOWN = True

models.py (database relational model)

from init import db

class flight(db.Model):
tablename ='flight'
#Table name_id = db.Column(db.Integer(),primary_key=True)
#Field , primary key_name = db.Column(db.String(255)) # field
_year = db.Column (db.String (255) ) # field
_count = db.Column (db.Integer ()) # field

#对象属性
def __repr__(self):
    return '<flight %s>'%self._name

app.py (main method to run the module)

#导包
from init import app,db
from models import flight
from flask import render_template
#路由路径
@app.route(’/’)
def index():
data = db.session.query(flight).all()
res_val = {}
for i in data:
res_val[i._name] = [x._count for x in db.session.query(flight).filter(flight._name == i._name).all()]
return render_template(‘index7.html’,res_val=res_val)

if name == ‘main’:
app.run(debug=True)

Guess you like

Origin blog.csdn.net/weixin_46073538/article/details/109329815