我刚刚开始学习 Flask,我正在尝试创建一个表单,该表单将允许POST method.
这是我的方法:
@app.route('/template', methods=['GET', 'POST'])
def template():
if request.method == 'POST':
return("Hello")
return render_template('index.html')
And my index.html
:
<html>
<head>
<title> Title </title>
</head>
<body>
Enter Python to execute:
<form action="/" method="post">
<input type="text" name="expression" />
<input type="submit" value="Execute" />
</form>
</body>
</html>
加载表单(在收到时呈现它GET) 工作正常。当我点击submit按钮但是,我得到一个POST 405 error Method Not Allowed
.
为什么不显示"Hello"?
您的表格正在提交至/
当该方法被路由为/template
除非这是一个拼写错误,否则您应该调整您的表格action
属性指向template
view: action="{{ url_for('template') }}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)