Bottle: Python Web Framework

63 comments · 94% upvoted · source · other discussions

comments

beam

In web.py you define all your routes in an array, as the first argument to the web.application method. Each route also gets an associated class. In Bottle, each route is defined by a function decorator and is associated with a function. You could see that by comparing the front pages of both web sites.

xamdam

Thanks. I guess I was wondering what the advantage or specialization is

mitsuhiko

The downside of the decorators is, that you have to import all the views before the server runs for the registration to kick in. The advantage is that the URL rule is closer to the function.

defnull

In bottle, you can add new routes at any time, even from within a callback while the server is running. If you want to define your callbacks first and add the routes later, you can use the decorator as a normal function:

def func():
  return "Hello World!"
...
bottle.route('/url')(func)

It is possible to simulate the web.py or django behavior (routes stored in a list) with import and a simple a for-loop, if you really want that.

mitsuhiko

Obviously that will work. However, that is completely irrelevant to the discussion decorator or explicit mapping. One can easily be converted to the other.