Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yubessy/fbb42a8aaff39c4f58fa to your computer and use it in GitHub Desktop.
Save yubessy/fbb42a8aaff39c4f58fa to your computer and use it in GitHub Desktop.
PythonのbottleでBASIC認証 ref: http://qiita.com/yubessy/items/33789eccb35b659b0b4e
$ python hello.py
# -*- 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)
python hello.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment