当前位置:网站首页>Build personal website based on flask

Build personal website based on flask

2022-07-07 07:28:00 Draw a circle to curse you yebo

One , install

pip install flask
1
Two , Import

from flask import Flask
1
3、 ... and , Add route

app = Flask(__name__)

@app.route("/",methods=['GET','POST'])
def index():
    return "......"
Four , Set the port and port ip

app.run(host="0.0.0.0",
        port=8080)
Click to run such a simple page and it will succeed

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()

Design web code

<!doctype html>
<html>
	<head>
	<meta charset="utf-8">
	<title> Film data in recent three years </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">  Page loading ... </div>
    </div>
<div class="head">
      <h1><img src="static/picture/logo.png">2019 The highest annual score 15 Movie data </h1>
      <div class="weather"><img src="static/picture/weather.png"><span> Cloudy to drizzle </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 Annual quantity </a></li>
            <li><a href="/movie_7">2020 Annual quantity </a></li>
            <li><a href="/movie_8">2021 Annual quantity </a></li>
            <li><a href="/movie_4"> Go to the next page </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">
    //  Based on the prepared dom, initialization echarts example 
    var myChart = echarts.init(document.getElementById('bottom'));
              //  Specify configuration items and data for the chart 
     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 //  The number of text displayed in a single line 
             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>

原网站

版权声明
本文为[Draw a circle to curse you yebo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070340314775.html