【发布时间】:2014-05-08 22:05:34
【问题描述】:
我正在浏览 Flask 入门教程并遇到错误。 ' 命令行中更完整的错误消息是:“GET /signup HTTP/1.1”405”。从这两个文件中知道我哪里出错了吗? http://opentechschool.github.io/python-flask/core/form-submission.html
<!-- index.html in the templates folder -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cats Everywhere!</title>
<link href='http://fonts.googleapis.com/css?family=Sintony:400,700' rel='stylesheet' type='text/css'>
<style type="text/css">
body
{
background-color:#000;
}
h1
{
font-size:48px;
margin-top:0;
font-family:Arial, sans-serif;
text-shadow:2px 0 15px #292929;
letter-spacing:4px;
text-decoration:none;
color:#DDD;
}
#banner
{
width:500px;
height:200px;
text-align:center;
background-image:url(http://i.imgur.com/MQHYB.jpg);
background-repeat:no-repeat;
border-radius:5px;
margin:90px auto auto;
padding:80px 0;
}
.lead
{
background-color:rgba(255,255,255,0.6);
border-radius:3px;
box-shadow:rgba(0,0,0,0.2) 0 1px 3px;
font-family:Sintony, sans-serif;
}
</style>
</head>
<body>
<div id="banner">
<h1>cats everywhere</h1>
<p class="lead">We're bringing cats to the internet. Free. Cute. Awesome.</p>
</div>
<div id="emailform">
<form action="/signup" method="post">
<input type="text" name="email"></input>
<input type="submit" value="Signup"></input>
</form>
</div>
</body>
</html>
#catseverywhere.py file:
from flask import Flask, render_template
from flask import request, redirect
app = Flask(__name__)
@app.route('/')
def hello_world():
author = "Me"
name = "RandomName"
return render_template('index.html', author=author, name=name)
@app.route('/signup', methods = ['POST'])
def signup():
email = request.form['email']
print("The email address is '" + email + "'")
return redirect('/')
if __name__ == '__main__':
app.run()
【问题讨论】:
-
返回 405 的确切 URL 是什么? Flask 在控制台中告诉你访问了哪些 URL。
-
命令行中更完整的错误信息是:"GET /signup HTTP/1.1" 405
-
不过,您可能希望将其添加到您的帖子中。
-
我无法使用您发布的代码重现您的错误;表格按设计工作。控制台打印
The email address is 'abcd'和127.0.0.1 - - [08/May/2014 15:00:57] "POST /signup HTTP/1.1" 302 -(302 是重定向)。 -
很高兴知道。谢谢。