Last active
August 29, 2015 14:01
-
-
Save yubessy/fbb42a8aaff39c4f58fa to your computer and use it in GitHub Desktop.
PythonのbottleでBASIC認証 ref: http://qiita.com/yubessy/items/33789eccb35b659b0b4e
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
$ python hello.py |
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
# -*- coding: utf-8 -*- | |
import bottle | |
# BASIC認証のユーザ名とパスワード | |
USERNAME = "user" | |
PASSWORD = "pass" | |
def check(username, password): | |
u""" | |
BASIC認証のユーザ名とパスワードをチェック | |
@bottle.auth_basic(check)で適用 | |
""" | |
return username == USERNAME and password == PASSWORD | |
@bottle.route("/hello") | |
@bottle.auth_basic(check) | |
def hello(): | |
return "hello" | |
if __name__ == '__main__': | |
bottle.run(host='localhost', port=8080, debug=True) |
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
python hello.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment