BASIC authentication can be applied by using bottle.auth_basic as a decorator. Requires v0.12 or higher.
hello.py
# -*- coding: utf-8 -*-
import bottle
#BASIC authentication username and password
USERNAME = "user"
PASSWORD = "pass"
def check(username, password):
u"""
Check BASIC authentication username and password
@bottle.auth_basic(check)Apply in
"""
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)
Run
$ python hello.py
Recommended Posts