Flask+MySQL+ECharts实现地名关系图谱
作者:互联网
先上数据结构表
功能点
1、所有地名关系动态图
2、将鼠标放到节点上会从数据库中把地名介绍显示
3、点击左侧边栏城市名称可把响应的数据显示
4、在搜索框内输入相应的地区可以查找响应节点
manage.py
from flask import Flask, abort, render_template
import os
from flask_sqlalchemy import SQLAlchemy
import pymysql
from app import app
pymysql.install_as_MySQLdb()
# 使用集成方式处理SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@localhost:3306/tibetmedicine?charset=utf8'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# 实例化db对象
db = SQLAlchemy(app)
# 定义404界面
@app.errorhandler(404)
def page_not_found(e):
return render_template('error-404.html')
# 定义500界面
@app.errorhandler(500)
def page_not_found(e):
return render_template('error-500.html')
# 定义文章类型函数,供模板页面调用
@app.context_processor
def gettype():
type = {
'1': '西藏自治区',
'2': '拉萨市',
'3': '林芝市',
'4': '昌都市',
'5': '那曲市',
'6': '山南市',
'7': '日喀则市',
'8': '阿里地区'
}
return dict(area_name=type)
if __name__ == "__main__":
from app.controller.indexCotroller import *
app.register_blueprint(index)
app.run(debug=True)
views.py
from flask import render_template, request, url_for, redirect, make_response, session
from .common.utility import ImageCode
from .dbUtils import getTargetDatas as gtd
from . import app
from .module.areas import Areas
from .module.links import Links
@app.route("/index")
def index():
areas = Areas()
result = areas.find_records()
links = Links()
data_links = links.find_records()
return render_template('index.html', result=result, data_links=data_links)
# 定义一个路由器来进行动态添加数据库数据
@app.route('/addAreasChinese', methods=['POST', 'GET'])
def addAreasChinese():
if request.method == 'POST':
areaName = request.form.get('areaName')
cityId = request.form.get('cityId')
gtd.insertChineseArea(areaName, cityId)
return redirect(url_for('index'))
# 定义一个路由器来进行进入藏语版知识图谱
@app.route('/changeTibet')
def changeTibet():
# 获取数据库里面的城市列表
city_list = gtd.getAllCityTibet()
# 获取数据库里面的区域列表
lasa_areas_list = gtd.getAllAreasTibet(1)
linzhi_areas_list = gtd.getAllAreasTibet(2)
changdu_areas_list = gtd.getAllAreasTibet(3)
naqu_areas_list = gtd.getAllAreasTibet(4)
shannan_areas_list = gtd.getAllAreasTibet(5)
rikaze_areas_list = gtd.getAllAreasTibet(6)
ali_areas_list = gtd.getAllAreasTibet(7)
return render_template('indexTibet.html',
title='首页',
city_list=city_list,
lasa_areas_list=lasa_areas_list,
linzhi_areas_list=linzhi_areas_list,
changdu_areas_list=changdu_areas_list,
naqu_areas_list=naqu_areas_list,
shannan_areas_list=shannan_areas_list,
rikaze_areas_list=rikaze_areas_list,
ali_areas_list=ali_areas_list)
# 定义一个路由器来进行动态添加数据库数据藏文
@app.route('/addAreasTibet', methods=['POST', 'GET'])
def addAreasTibet():
if request.method == 'POST':
areaName = request.form.get('areaName')
cityId = request.form.get('cityId')
gtd.insertTibetArea(areaName, cityId)
return redirect(url_for('changeTibet'))
标签:gtd,Flask,app,list,return,MySQL,import,ECharts,areas 来源: https://blog.csdn.net/qq_38957497/article/details/115197118