Bottle: Default Application

Bottle: Default Application


Bottle may have some instances of applications made, however for comfort the first instance is made for you; that is the default application. Bottle keeps these instances in a stack inward to the module. At whatever point you accomplish something with Bottle, (for example, running the application or appending a route) and don't determine which application you're discussing, it alludes to the default application.


Bottle offers an explicit way to build applications as follows:



By doing so, we are separating the application objects. This enhances re-usability a lot as other developers can safely import the app object from your code and can use Bottle.mount()  to join applications together.


The chance of various applications may appear to be confusing at first glance, however, they add versatility and adaptability to Bottle. For various modules of your application, you may make particular Bottle applications by instantiating other Bottle classes and setting them up with various configurations as needed. These diverse applications could be accessed by various URLs, through Bottle's URL router.

All of the Bottle instances are maintained in a global stack and the top of the stack is used as a default for some of the module-level functions and decorators.

For example in the code below, the route() decorator is a shortcut for calling Bottle.route() on the default application.


This is convenient for small applications but as soon as the module is imported, routes are installed to the global default application which causes import side-effects.