numpy 如何访问 flask 应用程序的用户输入[重复]

vx6bjr1n  于 2022-12-26  发布在  其他
关注(0)|答案(1)|浏览(95)
    • 此问题已存在**:

How to access user Input as GET request and output the responce in HTML page using Flask Python [duplicate]
2天前关闭。
我正在构建小型Web应用程序,因为我需要添加动态功能,我该如何做到这一点呢?这是我的静态脚本

import numpy as np
from flask import Flask, render_template, request
app = Flask(__name__)
x = np.array([0, 7, 18, 24, 26, 27, 26, 25, 26, 16, 20, 16, 23, 33, 27, 27,
22, 26, 27, 26, 25, 24, 25, 26, 23, 25, 26, 24, 23, 12, 22, 11, 15, 24, 11,
12, 11, 27, 19, 25, 26, 21, 23, 26, 13, 9, 22, 18, 23, 26, 26, 25, 10, 22,
27, 25, 19, 10, 15, 20, 21, 13, 16, 16, 15, 19, 17, 20, 24, 26, 20, 23, 23,
25, 19, 15, 16, 27, 26, 27, 28, 24, 23, 24, 27, 28, 30, 31, 30, 9, 0, 11,
16, 25, 25, 22, 25, 25, 11, 15, 24, 24, 24, 17, 0, 23, 21, 0, 24, 26, 24,
26, 26, 26, 24, 25, 24, 24, 22, 22, 22, 23, 24, 26,23])
@app.route('/')
def main():
    return render_template('index.html',count_result=get_count(x))
@app.route('/', methods=['GET','POST'])
def get_count(id_count):
    if request.method=="POST":
        sub_lists = np.split(x, np.where(np.diff(x) < 0)[0] + 1)
        id_count = 0
        id_list = []
        for unit in sub_lists:
           if min(unit) == 0 and max(unit) > 20 and len(set(unit)) > 1:
            id_count += 1
            id_list.append(unit)
    return id_count
    return render_template("index.html",get_count=id_count(x))
if __name__=="__main__":
    app.run(debug=False, port=1223)

以上脚本值为min(单位)和最大值(单位)i已保存为静态值,并且i能够获取id_count(循环计数)值,如果用户更改最小值(单位)和最大值(单位)必须有id_count,假设用户将最小值(单位)和最大值(单位)值id_计数来了,我怎么能做的html脚本,我不提形式输入到 flask 应用程序,任何想法如何获得是工作,感谢先进

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>Acceleration Count using Speed and Time Data</h2>
<form method=post enctype=multipart/form-data>
        <label for="input1">enter first input:</label>

        <input type="text" id="input1" name="min(unit)" >
                 <label for="input2">enter second  input:</label>

        <input type="text" id="input2" name="max(unit)" >
    <h>the acceleration count lower end bilow 0 to 13 and upper end limits in between above 18 and bilow 26 is.....{{count_result}} </h>

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

nx7onnlm1#

通过输入名称获取输入值。

request.form.get('min(unit)')

顺便说一句,你需要把表单操作设置为你的后端路径。类似于:

<form action="/get_count">

还有另外一种方法来设置表单操作和获取输入值。你可以在这里的文档或其他答案中看到

相关问题