当前位置:网站首页>基于Flask搭建个人网站
基于Flask搭建个人网站
2022-07-07 03:40:00 【画个圈圈诅咒你 yebo】
一,安装
pip install flask
1
二,导入
from flask import Flask
1
三,添加路由
app = Flask(__name__)
@app.route("/",methods=['GET','POST'])
def index():
return "......"
四,设置端口和ip
app.run(host="0.0.0.0",
port=8080)
点击运行这样一个简单的页面就成功了
app.py
import pymysql
from flask import render_template, Flask
app=Flask(__name__)
@app.route('/')
def movie_1():
name = []
score = []
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from 2019_top_15;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
name.append(str(item[0]))
score.append(item[1])
# print(name)
# print()
cur.close()
con.commit()
con.close()
return render_template('movie_1.html',name=name,score=score)
@app.route('/movie_2')
def movie_2():
name = []
score = []
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from 2020_top_15;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
name.append(str(item[0]))
score.append(item[1])
# print(name)
# print()
cur.close()
con.commit()
con.close()
return render_template('movie_2.html', name=name, score=score)
@app.route('/movie_3')
def movie_3():
name = []
score = []
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from 2021_top_15;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
name.append(str(item[0]))
score.append(item[1])
# print(name)
# print()
cur.close()
con.commit()
con.close()
return render_template('movie_3.html', name=name, score=score)
@app.route('/movie_4')
def movie_4():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from dalu;"
data=cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_4.html',s=s)
@app.route('/movie_taiwan')
def movie_taiwan():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from taiwan;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_taiwan.html', s=s)
@app.route('/movie_meiguo')
def movie_meiguo():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from meiguo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_meiguo.html', s=s)
@app.route('/movie_yingguo')
def movie_yingguo():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from yingguo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_yingguo.html', s=s)
@app.route('/movie_riben')
def movie_riben():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from riben;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_riben.html', s=s)
@app.route('/movie_taiguo')
def movie_taiguo():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from taiguo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_taiguo.html', s=s)
@app.route('/movie_hanguo')
def movie_hanguo():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from hanguo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_hanguo.html', s=s)
@app.route('/movie_faguo')
def movie_faguo():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from faguo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_faguo.html', s=s)
@app.route('/movie_xiju')
def movie_xiju():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiju;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiju.html', s=s)
@app.route('/movie_yinyue')
def movie_yinyue():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from yinyue;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_yinyue.html', s=s)
@app.route('/movie_yundong')
def movie_yundong():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from yundong;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_yundong.html', s=s)
@app.route('/movie_zhenrenxiu')
def movie_zhenrenxiu():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from zhenrenxiu;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_zhenrenxiu.html', s=s)
@app.route('/movie_gewu')
def movie_gewu():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from gewu;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_gewu.html', s=s)
@app.route('/movie_donghua')
def movie_donghua():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from donghua;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_donghua.html', s=s)
@app.route('/movie_kehuan')
def movie_kehuan():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from kehuan;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_kehuan.html', s=s)
@app.route('/movie_six')
def movie_six():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from six;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_six.html', s=s)
@app.route('/movie_five')
def movie_five():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from five;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_five.html', s=s)
@app.route('/movie_seven')
def movie_seven():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from seven;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_seven.html', s=s)
@app.route('/movie_eight')
def movie_eight():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from eight;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_eight.html', s=s)
@app.route('/movie_nine')
def movie_nine():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from nine;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_nine.html', s=s)
@app.route('/movie_xiaoyu100')
def movie_xiaoyu100():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiaoyu100;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiaoyu100.html', s=s)
@app.route('/movie_xiaoyu150')
def movie_xiaoyu150():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiaoyu150;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiaoyu150.html', s=s)
@app.route('/movie_xiaoyu200')
def movie_xiaoyu200():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiaoyu200;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiaoyu200.html', s=s)
@app.route('/movie_xiaoyu250')
def movie_xiaoyu250():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiaoyu250;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiaoyu250.html', s=s)
@app.route('/movie_xiaoyu300')
def movie_xiaoyu300():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from xiaoyu300;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_xiaoyu300.html', s=s)
@app.route('/movie_over300')
def movie_over300():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from over300;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_over300.html', s=s)
@app.route('/movie_film_2019')
def movie_film_2019():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from film_2019;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_film_2019.html', s=s)
@app.route('/movie_film_2020')
def movie_film_2020():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from film_2020;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_film_2020.html', s=s)
@app.route('/movie_film_2021')
def movie_film_2021():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from film_2021;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
# print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_film_2021.html', s=s)
@app.route('/movie_5')
def movie_5():
s = []
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from app01_userinfo;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
s.append(item)
print(s)
cur.close()
con.commit()
con.close()
return render_template('movie_5.html', movies=s)
@app.route('/movie_6')
def movie_6():
datas={}
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from pie_1;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
datas[item[0]]=item[1]
print(datas)
cur.close()
con.commit()
con.close()
return render_template('movie_6.html', datas=datas)
@app.route('/movie_7')
def movie_7():
datas = {}
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from pie_2;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
datas[item[0]] = item[1]
print(datas)
cur.close()
con.commit()
con.close()
return render_template('movie_7.html', datas=datas)
@app.route('/movie_8')
def movie_8():
datas = {}
con = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456789',
db='design',
charset='utf8'
)
cur = con.cursor()
sql = "select * from pie_3;"
data = cur.execute(sql)
result = cur.fetchall()
for item in result:
datas[item[0]] = item[1]
print(datas)
cur.close()
con.commit()
con.close()
return render_template('movie_8.html', datas=datas)
if __name__=='__main__':
app.run()
设计网页代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>近三年电影数据</title>
<script type="text/javascript" src="static/js/jquery.js"></script>
<link rel="stylesheet" href="static/css/style.css">
</head>
<script type="text/javascript">
</script>
<body>
<div class="loading">
<div class="loadbox"> <img src="static/picture/loading.gif"> 页面加载中... </div>
</div>
<div class="head">
<h1><img src="static/picture/logo.png">2019年评分最高的15部电影数据</h1>
<div class="weather"><img src="static/picture/weather.png"><span>多云转小雨</span><span>2022-07-01</span></div>
</div>
<div class="top">
<nav>
<ul class="nav">
<li><a href="/">2019</a></li>
<li><a href="/movie_2">2020</a></li>
<li><a href="/movie_3">2021</a></li>
<li><a href="/movie_6">2019年数量</a></li>
<li><a href="/movie_7">2020年数量</a></li>
<li><a href="/movie_8">2021年数量</a></li>
<li><a href="/movie_4">前往下一页</a></li>
</ul>
</nav>
</div>
<div id="bottom"style="width: 1500px;height: 600px;">
</div>
<script language="JavaScript" src="static/js/js.js"></script>
<script type="text/javascript" src="static/js/echarts.min.js"></script>
<script type="text/javascript" src="static/js/china.js"></script>
<script type="text/javascript" src="static/js/area_echarts.js"></script>
<script type="text/javascript" src="static/js/jquery.waypoints.min.js"></script>
<script type="text/javascript" src="static/js/jquery.countup.min.js"></script>
</body>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('bottom'));
// 指定图表的配置项和数据
myChart.setOption({
xAxis: {
type: 'category',
data: {
{ name|tojson }},
axisLabel:{
textStyle:{
color:'white'
},
interval:0,
formatter:function (params) {
var newParamsName=''
const paramsNameNumber=params.length
const provideNumber = 6 // 单行显示文字个数
const rowNumber = Math.ceil(paramsNameNumber / provideNumber)
if (paramsNameNumber > provideNumber) {
for (let p = 0; p < rowNumber; p++) {
var tempStr = ''
var start = p * provideNumber
var end = start + provideNumber
if (p === rowNumber - 1) {
tempStr = params.substring(start, paramsNameNumber)
} else {
tempStr = params.substring(start, end) + '\n'
}
newParamsName += tempStr
}
} else {
newParamsName = params
}
return newParamsName
}
}
},
yAxis: {
type: 'value',
axisLabel:{
textStyle:{
color:'white'
}
}
},
series: [
{
data: {
{ score|tojson }},
type: 'bar',
barWidth:40,
showBackground: true,
backgroundStyle: {
color: '#409EFF'
},
label:{
show:true,
position:'top',
color:'white'
},
itemStyle: {
color:'#409EFF'
}
}]
})
</script>
</html>
边栏推荐
- Basic process of network transmission using tcp/ip four layer model
- ViewModelProvider. Of obsolete solution
- Detailed explanation of transform origin attribute
- sql中对集合进行非空校验
- Lm11 reconstruction of K-line and construction of timing trading strategy
- Esxi attaching mobile (Mechanical) hard disk detailed tutorial
- Mobx knowledge point collection case (quick start)
- transform-origin属性详解
- . Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context
- URP - shaders and materials - light shader lit
猜你喜欢
07_ Handout on the essence and practical skills of text measurement and geometric transformation
Academic report series (VI) - autonomous driving on the journey to full autonomy
Sqlmap tutorial (IV) practical skills three: bypass the firewall
三、高质量编程与性能调优实战 青训营笔记
Apache AB stress test
Advanced practice of C language (high level) pointer
Network foundation - header, encapsulation and unpacking
Asynchronous components and suspend (in real development)
[semantic segmentation] - multi-scale attention
面试官:你都了解哪些开发模型?
随机推荐
Torefs API and toref API
点亮显示屏的几个重要步骤
Unity3d learning notes
抽絲剝繭C語言(高階)指針的進階
Sqlmap tutorial (IV) practical skills three: bypass the firewall
[Luogu p1971] rabbit and egg game (bipartite game)
Kuboard can't send email and nail alarm problem is solved
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.10 tabbar component (I) how to open and use the default tabbar comp
Outlier detection technology of time series data
計算機服務中缺失MySQL服務
How to reduce inventory with high concurrency on the Internet
Hidden Markov model (HMM) learning notes
[explanation of JDBC and internal classes]
Several important steps to light up the display
Networkx drawing and common library function coordinate drawing
Release notes of JMeter version 5.5
Introduction to abnova's in vitro mRNA transcription workflow and capping method
软件验收测试
leetcode 509. Fibonacci number
记一个并发规则验证实现