Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTTP 400中的基本表单-Python 3.5_Python_Forms_Python 3.x_Flask_Webpage - Fatal编程技术网

HTTP 400中的基本表单-Python 3.5

HTTP 400中的基本表单-Python 3.5,python,forms,python-3.x,flask,webpage,Python,Forms,Python 3.x,Flask,Webpage,我是新来的,花了几个小时试图在Flask中为Python 3.5设置一个表单。我希望用户能够输入一个温度设定点,然后单击submit按钮,并将该值存储在变量中。 我在名为index.html的模板文件中有此代码: <html> <body> <p><font size="6">Jewell Hot-Tub Controller</font> <br> <font size="4">Wate

我是新来的,花了几个小时试图在Flask中为Python 3.5设置一个表单。我希望用户能够输入一个温度设定点,然后单击submit按钮,并将该值存储在变量中。 我在名为
index.html
的模板文件中有此代码:

<html>
<body>
    <p><font size="6">Jewell Hot-Tub Controller</font>
    <br>
    <font size="4">Water Temperature: {{water_temp}}</p>
    <br>
    <font size="4">Set Point: {{set_point}}</p>
    <br>
    <font size="4">Enter New Set Point:</p>
    <form class="form-newtemp" method="get" action="/ChangeTemp">
        <input type="text" id="new_sp" name="new_sp" size="5" placeholder="New Temp." required>
        <input id="1submit" type="submit">
    </form>
</body>
</html>
文本框中输入“27”会将浏览器发送到
400错误请求
页面:

http://127.0.0.1:5000/ChangeTemp?new_sp=27
为什么这会更改错误请求错误,而不是返回值?我看到的教程使用了
POST
,但我使用了
GET
,这需要不同的语法吗? 另外,如果有任何事情是混乱的,或者做错了,请告诉我。 谢谢大家!


编辑:我还尝试了“request.form.get('new-sp',new)”,这会导致500个内部服务器错误。

有多种方法可以解决您的问题。我想最快的方法是:

<form class="form-newtemp" method="post" action="{{ url_for('process')}}">
或者,您可以不更改模板,并且:

@app.route('/ChangeTemp', methods=['GET'])
def process():
    new = request.args.get('new_sp')
    return 'New set point is:' + new

看看url的末尾,您正在更改它,但还没有准备好进行更改。编辑您的表单以使用
POST
方法发送表单,并使用您的url获取
POST
方法,或在url上添加所需的编辑。对不起,我不明白。你能不能帮我把话说清楚?为什么这件事被否决了?
@app.route('/ChangeTemp', methods=['POST])
def process():
    new = request.form['new_sp']
    return 'New set point is:' + new
@app.route('/ChangeTemp', methods=['GET'])
def process():
    new = request.args.get('new_sp')
    return 'New set point is:' + new