【问题标题】:Python: Retrieve the current URL from the browser using bottle frameworkPython:使用瓶子框架从浏览器中检索当前 URL
【发布时间】:2016-03-24 05:16:27
【问题描述】:

我正在寻找使用瓶子框架检索浏览器的完整 url。检查了文档,发现最好的方法是使用geturl() 方法。我该怎么办?

【问题讨论】:

    标签: python url urllib2 bottle


    【解决方案1】:

    bottle.request.url 返回网址。 (它在幕后调用geturl。)

    from bottle import Bottle, request
    
    app = Bottle()
    
    @app.route('/')
    def root():
        return ['this url is: {}'.format(request.url)]
    
    app.run(host='0.0.0.0', port=8080)
    

    在行动:

    % python test.py &
    Bottle v0.12.8 server starting up (using WSGIRefServer())...
    Listening on http://0.0.0.0:8080/
    Hit Ctrl-C to quit.
    
    % curl 'http://localhost:8080/?hello'
    this url is: http://localhost:8080/?hello
    

    【讨论】:

    • 非常感谢您。在这种情况下,返回是一个列表还是一个字符串?
    • 不客气!它返回一个字符串列表。有关说明,请参阅 this
    猜你喜欢
    • 2020-06-26
    • 2015-08-09
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 2018-03-22
    • 2014-11-05
    相关资源
    最近更新 更多