Tauseef Hussain
Tauseef Hussain

Reputation: 1079

Python: Retrieve the current URL from the browser using bottle framework

I am looking to retrieve the complete url of the browser using the bottle framework. Checked the documentation and found out the best way is to use the geturl() method. How should I go about this?

Upvotes: 3

Views: 2729

Answers (1)

ron rothman
ron rothman

Reputation: 18128

bottle.request.url returns the url. (It calls geturl behind the scenes.)

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)

In action:

% 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

Upvotes: 4

Related Questions