【发布时间】:2018-07-26 07:02:59
【问题描述】:
我目前正在将 pythonanywhere 用于学校项目。以下是我遇到问题的一段代码。
#When at www.example.com/ load "log_in.html" file
@app.route("/", methods=["GET"])
def index():
if request.method == "GET":
return render_template("log_in.html")
#When at www.example.com/create_account/
@app.route("/create_account", methods=["GET", "POST"])
def create_account():
if request.method == "GET":
return render_template("create_account.html", username = username, password = password)
return redirect(url_for('index'))
用户点击按钮并提交详细信息以创建帐户的意图是什么。数据被记录后,会被重定向回'index'下的登录页面。
在测试代码后,一切正常,直到重定向部分给我一个错误 405,方法不允许。
该网站位于http://fishypower.pythonanywhere.com/create_account 单击“创建帐户”按钮将给出错误 405
下面是http://fishypower.pythonanywhere.com/create_account的代码
<html>
<head>
<title>ElderMinder: Create Account</title>
</head>
<body>
<div>
<form action="." method="POST">
<center><textarea name="username" placeholder="Enter your username"></textarea></center>
<div></div>
<center><textarea name="password" placeholder="Enter your password"></textarea></center>
<div></div>
<center><input type="submit" value="Create Account"></center>
</form>
</div>
</body>
</html>
【问题讨论】:
标签: flask http-status-code-405