我刚刚开始学习Flask,并且我正在尝试创建一种允许POST方法的表单。
这是我的方法:
@app.route('/template', methods=['GET', 'POST'])
def template():
if request.method == 'POST':
return("Hello")
return render_template('index.html')
而我的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时将其呈现)可以正常工作。但是,当我单击“ 提交”按钮时,出现一个POST 405 error Method Not Allowed
。
为什么不显示“ Hello”?
除非是错字,否则您的表单将提交给/
路由方法,/template
除非您输入错误,否则应调整表单的action
属性以指向template
视图:action="{{ url_for('template') }}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句