在编辑一个html文件时,修改一下内容:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="https://localhost/5000" method="post"> <!--这里一改url_for 就报错 ?-->
<p>姓名:<input type="text" name="姓名"></p>
<p>年龄:<input type="text" name="年龄"></p>
<p>性别:<input type="text" name="性别"></p>
<p>地址:<input type="text" name="地址"></p>
<p><input type="submit" value="提交"></p>
</form>
</body>
</html>
app.py中的代码为:
```python
#表单提交
@app.route('/test/register')
def test1():
return render_template('test/register.html')
#接受表单路由 指定methods
@app.route('/result',methods=['POST','GET'])
def test2():
if request.method=='POST':
result=request.form
return render_template('test/result.html',result=result)
if __name__ == '__main__':
app.run(debug=True)
把action属性后面的url改成:url_for(’result‘) 就会报错 ,报错内容为:
werkzeug.routing.exceptions.BuildError: Could not build url for endpoint '/result'. Did you mean 'test1' instead?