2015-12-17 39 views

回答

2

bottle.request.url返回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 
+0

谢谢你这么多了点。在这种情况下,返回是一个列表还是一个字符串? –

+1

不客气!它返回一个字符串列表。请参阅[this](http://bottlepy.org/docs/dev/tutorial.html#generating-content)以获取解释。 –

相关问题