Created
March 29, 2018 12:57
-
-
Save Raykeymas/e1a422ee8b4b9a37fdde181119d841de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#必要なライブラリのインポート | |
from flask import Flask | |
from flask_httpauth import HTTPBasicAuth #HTTP"Basic"Auth | |
#Flask、HTTPBasicAuthクラスのインスタンスを作成 | |
app = Flask(__name__) | |
auth = HTTPBasicAuth() | |
#"id":"パスワード" | |
id_list = { | |
"Tanaka": "1111", | |
"Suzuki": "1234" | |
} | |
#入力されたidに該当するパスワードを | |
#比較のために取得する | |
@auth.get_password | |
def get_pw(id): | |
if id in id_list: | |
return id_list.get(id) | |
return None | |
#実際の処理部分 | |
@app.route('/') | |
@auth.login_required #ここで認証が行われる | |
#認証に成功したら以下の処理を実行する | |
def index(): | |
return "Hello, %s!" % auth.username() | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment