简单的网页开发之一
建立一个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>