zoukankan      html  css  js  c++  java
  • flask处理数据,页面实时刷新展示

    背景:

    后端 flask(python)处理数据,页面实时刷新,类似于打包页面的动态展示,展示效果如图:

    代码如下:

    前端主要使用以下循环处理, 2--- 2秒刷新一次

    {% if 0 == stop %}
    <meta http-equiv="refresh" content="2;url={{ url_for('test') }}">
    {% endif %}

    html:

     1 <html>
     2 <head>
     3     {% if 0 == stop %}
     4     <meta http-equiv="refresh" content="2;url={{ url_for('test') }}">
     5     {% endif %}
     6 </head>
     7 <body>
     8 
     9 <div class="header">
    10     <h4>标题XXX</h4>
    11 </div>
    12 <div class="body">
    13     <form class="form" action="/test" method="post">
    14         <div class="form">
    15             <button class="btn btn-primary" type="submit" >开始</button>
    16         </div>
    17     </form>
    18 </div>
    19 
    20 <div class="c" id="show2" >
    21     <div class="header">
    22         <h4>结果展示:</h4>
    23         <p style="white-space:pre-line;">{{ s }}</p>
    24     </div>
    25 
    26 </div>
    27 </body>
    28 <!- 根据自己实际路径填写>
    29 <script type="text/javascript" src="static/js/main.min.js"></script>
    30 <script type="text/javascript" src="static/js/jquery.min.js"></script>
    31 
    32 <script type="text/javascript">
    33 
    34 
    35 </script>
    36 </html>

    python代码如下:

     1 from flask import Flask,render_template,request
     2 
     3 app = Flask(__name__)
     4 
     5 @app.route('/test',methods=['GET','POST'])
     6 def test():
     7     s = testDis()
     8     stop = 0
     9     # notify(access_token, ('调用地址:','tools_updateTimes'), ('调用名称','修改司机交易测试'),'','','','')
    10     if s == 'z':
    11         stop = 1
    12     return render_template("test/test.html",s = s,stop=stop)
    13 
    14 
    15 import random
    16 def testDis():
    17     s =random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
    18     if s == 'a':
    19         s = s+'
    '+s
    20     return s
    21 
    22 if __name__ == '__main__':
    23     app.run(host='0.0.0.0')
  • 相关阅读:
    Laya list 居中
    Laya for...in和for each...in
    idea中tomcat启动失败

    通过Mock测试控制器
    Mybatis查询sql传入一个字符串传参数,报There is no getter for property named 'ids' in 'class java.lang.String'。
    Application Server was not connected before run configuration stop, reason: Unable to ping server at localhost:1099
    System.getProperty("XXX")方法
    linux命令
    JDK,IDEA,Tomcat,maven,MySQL的安装
  • 原文地址:https://www.cnblogs.com/whycai/p/11772592.html
Copyright © 2011-2022 走看看