このプログラムで@ auth.verify_passwordデコレータがいつ、どのように使用されるのかを理解したい。 私がルートhttp://127.0.0.1:5000に移動すると、ユーザー名とパスワードを渡す必要があり、@ auth.login_requiredがそれを確認するが、@ auth.verify_passwordはどこに入っているのだろうと私は理解していますか?Flask-HTTPAuthのデコレータを理解する
@ auth.login_requiredはそれを呼び出しますか? the documentationから
#!/usr/bin/env python
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
app = Flask(__name__)
auth = HTTPBasicAuth()
users = {
"john": generate_password_hash("hello"),
"susan": generate_password_hash("bye")
}
@auth.verify_password
def verify_password(username, password):
if username in users:
return check_password_hash(users.get(username), password)
return False
@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % auth.username()
if __name__ == '__main__':
app.run()