ajax_bottle.py 780 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. """
  3. A simple application that shows how Bottle and jQuery get along.
  4. :copyright: (c) 2015 by Oz Nahum Tiram.
  5. :license: BSD, see LICENSE for more details.
  6. Inspired by the same example given in Flask
  7. :copyright: (c) 2015 by Armin Ronacher.
  8. """
  9. from bottle import route, run, debug, template, request
  10. import json
  11. @route('/_add_numbers')
  12. def add_numbers():
  13. """Add two numbers server side, ridiculous but well..."""
  14. a = request.params.get('a', 0, type=int)
  15. b = request.params.get('b', 0, type=int)
  16. return json.dumps({'result': a+b})
  17. @route('/foo/:no')
  18. def bar(no):
  19. return template('index.tpl', request=request)
  20. @route('/')
  21. def index():
  22. return template('index.tpl', request=request)
  23. debug(True)
  24. run(port=9030)