编程语言
首页 > 编程语言> > python网页之1

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>

标签:网页,val,python,sensor,result,return,post,data
来源: https://blog.csdn.net/ab459548764/article/details/122634266