-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (33 loc) · 981 Bytes
/
app.py
File metadata and controls
42 lines (33 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask
from flask import render_template
from flask import jsonify
from flask_cors import CORS
from flask_socketio import SocketIO, emit, disconnect
app = Flask(__name__)
app.config['SECRET_KEY'] = "windroc-nwpc-project"
CORS(app, resources=r'/*')
socketio = SocketIO(app, async_mode=None)
# 修改flask自带的模板渲染引擎方式 -> {{ ** }}
app.jinja_env.variable_start_string = '{{ '
app.jinja_env.variable_end_string = ' }}'
@app.route('/')
def hello_world():
return render_template('index.html')
@socketio.on('progress')
def progress():
import random
import time
for i in range(0, 5):
jd = random.randint(0, 150)
print(jd)
time.sleep(1)
socketio.sleep(0.1)
emit('pb', {'data': jd})
# emit('disconnect')
@socketio.on('close')
def test_connect():
print("disconnect")
disconnect()
if __name__ == '__main__':
# app.run()
socketio.run(app, host='localhost', port=8080)