Bottle 中的基本身份验证和将文件发送到用户的浏览器

Basic auth in Bottle & Sending a file to user's browser

我正在尝试在 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 函数是将文件发送到用户浏览器的正确方法吗?

i cannot retrieve the username given to the prompt as request.auth.username nor as request.auth.user. How can i grab that value?

According to the documentationrequest.auth(user, password)的元组。像这样检索用户名:

username = request.auth[0]