bottle Python HTTP Query-Parameter minimales Beispiel
Um den Wert eines Query-Parameters namens myparam in bottle abzurufen, zuerst request importieren:
bottle_query_params.py
from bottle import requestund dann verwenden
bottle_request_params_usage.py
request.params["myparam"]Vollständiges Beispiel:
bottle_query_server.py
#!/usr/bin/env python3
from bottle import route, run, request
@route('/test')
def hello():
query_param = request.params["myparam"]
return f"myparam is {query_param}"
run(host='localhost', port=8080, debug=True)Dieses Skript ausführen und http://localhost:8080/test?myparam=xyz im Browser öffnen – es wird Folgendes angezeigt
output.txt
myparam is xyzCheck out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow