首页 > 解决方案 > 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 函数也是将文件发送到用户浏览器的正确方法吗?

标签: pythonbottle

解决方案


我无法检索作为 request.auth.username 或 request.auth.user 提供给提示的用户名。我怎样才能抓住那个价值?

根据文档request.auth是 的元组(user, password)。像这样检索用户名:

username = request.auth[0]

推荐阅读