python网页之1

简单的网页开发之一

建立一个POST的部分code:

import requests
import numpy as np

def get():
    result = np.random.random()
    return result

def pack():
    result = get()
    post_data = {
        'value': result
    }
    return post_data

post_data = pack()
res = requests.post(url="http://127.0.0.1:5000/upload",data=post_data)
print(res.text)

定义一个网页

@app.route('/upload', methods = ['POST','GET'])
def upload():
    global sensor_val
    if request.method == 'POST':
        sensor_val = request.form['value']
        return "Success"
    elif request.method == 'GET':
        return render_template('new.html',sensor_val = sensor_val)

前端:

<!DOCTYPE html>
<html lang="en">

<body>
    <span>Sensor:={{sensor_val}}</span>
</body>

<script type="text/javascript">

</script>

</html>

上一篇:【活动操作指引】最高价值6000元新年礼包来啦!2021零门槛抢开发者加油包


下一篇:springboot(十九):使用Spring Boot Actuator监控应用