Данный пример отправляет POST запрос и получает json ответ.
# coding:utf8
from bottle import route, run, request
@route('/')
def main():
return """
<html>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.4.2.min.js" />
<script type="text/javascript" language="javascript">
function sendjs() {
$.post('/json',
{ a:5, b:'test' },
function(data) {
alert('a=' + data.a + ', b=' + data.b);
},
'json'
);
};
</script>
<body>
<input OnClick="sendjs()" type="submit" >
</body></html>
"""
@route('/json', method = "POST")
def myGetJson():
a = request.POST['a']
b = request.POST['b']
return {'a':b, 'b':a }
run(host = '', port = 8090, reloader = True)