我寫的這個論壇,我想驗證用戶名和密碼,但我有result.Method不允許該方法不適用於請求的URL。在瓶
hello.html的
<html lang='en'>
<head>
<meta charset="utf-8" />
<title>Hello</title>
</head>
{% if error %}
{{ error }}
{% endif %}
<body>
Hello
</body>
</html>
的方法是不允許的爲請求的URL。
<!DOCTYPE html>
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>welcome</title>
<link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<section id="content">
<form action="/login" method="post">
<h1>Login Form</h1>
<div>
<input type="text" placeholder="Username" required="" name="username" />
</div>
<div>
<input type="password" placeholder="Password" required="" name="password" />
</div>
<div>
<input type="submit" value="Log in" />
</div>
</form><!-- form -->
</section><!-- content -->
</div><!-- container -->
</body>
</html>
我寫了一個論壇:
在app.py:
from flask import Flask
from flask import request
from flask import render_template, redirect, url_for, request
APP = Flask(__name__)
@APP.route('/')
def login1():
return render_template('login1.html')
@APP.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
error = 'Invalid Credentials. Please try again.'
else:
return redirect(url_for('home'))
return render_template('hello.html', error=error)
if __name__ == '__main__':
APP.debug=True
APP.run()
我無法驗證輸入? 如何能幫我請
嘗試將@app.route('/?',methods = ['GET','POST'])'改爲'@ APP.route('/ login',methods = ['GET', 'POST'])'.and in html,'form action =「/ login」' – itzMEonTV 2015-04-05 20:08:45
我有同樣的結果 – 2015-04-05 20:10:31
你在'app.py'和'html'中都改過了嗎? – itzMEonTV 2015-04-05 20:14:01