在编辑一个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?
url_for函数正确的用法是:url_for('视图函数名字') ,所以html文件应该改成:
<form action="{{ url_for('test2') }}" method="post">
有帮助的话,请点采纳该答案~
【以下回答由 GPT 生成】
问题分析:根据给出的代码和问题描述,可以大致推断出可能的问题是在修改