Skip to content

Instantly share code, notes, and snippets.

@dunossauro
Created May 4, 2018 14:58
Show Gist options
  • Save dunossauro/c369990d96d364fb2970dfa14bd13bd5 to your computer and use it in GitHub Desktop.
Save dunossauro/c369990d96d364fb2970dfa14bd13bd5 to your computer and use it in GitHub Desktop.
Bottle merge route example
from bottle import Bottle
app = Bottle()
@app.get('/api/v1/test_route1')
def get_route1():
return '42'
from bottle import Bottle
app = Bottle()
@app.get('/api/v1/test_route2')
def get_route2():
return '42'
from bottle import Bottle, run
from routes import routes
app = Bottle()
app.merge(routes)
run(app)
from bottle import Bottle
from app_1 import app as app_1
from app_2 import app as app_2
routes = Bottle()
routes.merge(app_1)
routes.merge(app_2)
@WilliamStam
Copy link

WilliamStam commented Jul 4, 2020

i know this is old... but im stuck..

so if manage.py sets up the various stuff like config etc for the application then how do you reference those items that are setup in "manage.py" inside each app? or are wee supposed to set up config / app variables on each app every time?

manage.py

from bottle import Bottle, run

from routes import routes

app = Bottle()
app.my_value = "hello" # <---- must be accessible to all "apps"

app.merge(routes)

run(app)

app_1.py

from bottle import Bottle

app = Bottle()

@app.get('/api/v1/test_route1')
def get_route1():
    return app.my_value # <------- how would i get the value in here?

just short of setting up a "Base" class for it im not having much joy :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment