Bottle.py HTTP Auth?[英] Bottle.py HTTP Auth?

本文是小编为大家收集整理的关于Bottle.py HTTP Auth?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何获得我的瓶子. - 我需要保护它,但找不到任何howtos.

推荐答案

瓶具有内置auth_basic装饰器,可以在视图上使用:

from bottle import auth_basic, request, route

def check(user, pw):
    # Check user/pw here and return True/False

@route('/')
@auth_basic(check)
def home():
    return { 'data': request.auth }

其他推荐答案

github上有一些库,例如软木这应该有所帮助.集成可能比相关文章中建议的库更容易.

本文地址:https://www.itbaoku.cn/post/1578384.html

问题描述

How can I get my bottle.py app (Running in Paste or Cherrypy) to do HTTP (basic or digest) authentication? - I need to secure it, but cant find a any HOWTOs.

推荐答案

bottle has a built in auth_basic decorator that can be used on a view:

from bottle import auth_basic, request, route

def check(user, pw):
    # Check user/pw here and return True/False

@route('/')
@auth_basic(check)
def home():
    return { 'data': request.auth }

其他推荐答案

There are some libraries on GitHub like https://github.com/FedericoCeratto/bottle-cork that should help. It may be easier to integrate than the repoze library suggested in the related post.