安装镜像 参考:
https://blog.csdn.net/vinglemar/article/details/124698858
参考代码<下载>:
PrimeShow.py
from Lib import gcode from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') @app.route('/Index') def Index(): return render_template('Index.html') @app.route('/PrimeShow',methods = ['POST', 'GET']) def PrimeShow(): if request.method == 'POST': data= request.form imax=int(data["imax"]) primeList=gcode.getPrime(imax) return render_template("PrimeShow.html",primeList = primeList) if __name__ == '__main__': app.run(debug = True)
gcode.py
ef getPrime(imax): primeList=[2] bPrime=False for i in range(3,imax+1): bPrime=False for j in range(2,i): if i%j==0: bPrime=False break else: bPrime=True continue if(bPrime==True): primeList.append(i) return primeList print(getPrime(100))
Index.html:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>质数展示</title> <link rel="stylesheet" href="{{url_for('static',filename='bootstrap4/css/bootstrap.css')}}" type="text/css"> </head> <body> <div class="container mt-2"> <form action="/PrimeShow" method="POST"> <div class="card" class="row"> <div class="card-header"> 质数展示 </div> <div id="cardbody" class="card-body"> <h5 class="card-title">作者:gCode Teacher 标签</h5> <p id="tip" class="card-text"> <span class="badge badge-secondary">教师</span> <span class="badge badge-success">攻城狮</span> <span class="badge badge-danger">码农</span> <span class="badge badge-warning">体育爱好者</span> </p> <a href="http://www.exesoft.cn" class="btn btn-primary">官网:行易软件</a> </div> <div> <div class="col input-group mb-4"> <div class="input-group-prepend"> <label class="input-group-text" for="imax">给一个最大范围</label> </div> <input id="imax" name="imax" step="1" min="0" max="100" type="number" value="0" class="form-control"/> <input type = "submit" class="btn btn-primary" value = "submit" /> </div> </form> </div> </body> </html>
PrimeShow.html:
<!DOCTYPE html> <html> <head> <title>结果</title> <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"> <link rel="stylesheet" href="{{url_for('static',filename='bootstrap4/css/bootstrap.css')}}" type="text/css"> </head> <body> <div class="container mt-2"> <table class="table table-striped table-hover"> <tr> <th class="bg-primary">顺序</th><th class="bg-success">质数</th><th class="bg-danger">备注</th> </tr> {% for prime in primeList %} <tr> <td>{{loop.index}}</td><td>{{prime}}</td> <td> {% if prime%10==9 %} <span class="badge badge-warning"> 末尾数为9,好数字! </span> {% endif %} </td> </tr> {% endfor %} </table> </div> </body> </html>