【发布时间】:2012-08-24 03:52:12
【问题描述】:
我刚开始学习 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 时呈现它)工作正常。然而,当我点击 submit 按钮时,我得到一个POST 405 error Method Not Allowed。
为什么不显示“Hello”?
【问题讨论】: