0
にログインする代わりにエラーハンドラーを引き起こしています。関連するユーザー名とパスワードを使用してindex.htmlページにサインインしようとすると、エラーハンドラーが有効になり、サインインが受け入れられる代わりに404.htmlになります。間違ったユーザー名とパスワードのメッセージ。これは、正しいサインインが使用されているかどうかに関係なく発生します。単純なrequest.formが
私が迷っていることや間違っていることに関するアドバイスはありますか?
代わりにrequest.form.getまたはrequest.form.postを使用する必要がありますか?ここ
@app.errorhandler(404)
@app.errorhandler(500)
def errorpage(e):
return render_template('404.html')
def login_required(f):
@wraps(f)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return f(*args, **kwargs)
else:
flash('please login first.')
return redirect (url_for('index'))
return wrap
@app.route('/', methods=['GET','POST'])
def index():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'password':
error = 'invalid attempt.'
else:
session['logged_in'] = True
return redirect(url_for('admin'))
return render_template('index.html', error = error)
@app.route('/logout')
def logout():
session.pop('logged_in', None)
return render_template('/logout.html')
@app.route('/admin',methods=['GET','POST'])
@login_required
def admin():
は、関連のindex.html
<!DOCTYPE html>
<html lang="en"
<header>
<link rel="stylesheet" type="text/css" href="static/bootstrap.min.css" media='screen'>
<title>Login</title>
<h1>Welcome!</h1>
<h2>Sign in</h2>
</header>
<body>
<form action="/helloflask.py" method="post">
Username: <input type="text" placeholder="Username" name="username" value="{{ request.form.username }}"><br>
Password: <input type="text" placeholder="Password" name="password" value="{{ request.form.password }}"><br><br><br>
<input class= "btn btn-default" type="submit" value="Confirm">
</form>
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }} </p>
{% endif %}
</body>
</html>