我正在尝试在Bottle框架中执行基本身份验证
def is_authenticated_user(user, password):
# This function is called to check if a username/password combination is valid
return username == 'nikos' and password == ******'
并将其称为:
@app.route( '/file', methods=['POST'] )
@auth_basic( is_authenticated_user )
....
....
filename = request.form.get('filename') return static_file( filename, root='/home/nikos/wsgi/static/files' )
我在执行此工作时遇到麻烦,我不明白为什么我无法使用错误方法。也是static_file函数将文件发送到用户浏览器的正确方法吗?
答案 0 :(得分:1)
i无法检索作为给定提示的用户名,即request.auth.username或request.auth.user。我该如何获取这一价值?
According to the documentation,request.auth
是(user, password)
的元组。像这样检索用户名:
username = request.auth[0]