在Bottle中获取$ _SERVER ['HTTP_USER_AGENT']变量值

Ana*_*ghe 3 python bottle

我是python瓶子框架的新手,需要专门获得$ _SERVER ['HTTP_USER_AGENT']变量值.请问有人解释我怎样才能做到这一点.

小智 8

试试吧:

import request, route, run

@route('/user-agent')
def user_agent():
    return request.environ.get('HTTP_USER_AGENT')
run()
Run Code Online (Sandbox Code Playgroud)

  • 请缩进您的代码.这样做在python中不是可选的. (2认同)