Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bottle() and sub-apps w/ beaker #79

Closed
Nitesedge opened this issue Apr 5, 2015 · 1 comment
Closed

Bottle() and sub-apps w/ beaker #79

Nitesedge opened this issue Apr 5, 2015 · 1 comment

Comments

@Nitesedge
Copy link

I am trying to use bottle's object functionality to be able to import subapps and then mount them into the global default application. However, when I try to include beaker for session management I run into issues:


from bottle import Bottle
from beaker.middleware import SessionMiddleware

session_opts = {
    'session.type': 'file',
    'session.cookie_expires': 300,
    'session.data_dir': './data',
    'session.auto': True
}

app = Bottle()
app = SessionMiddleware(app, session_opts)

#Import Subapp
from subapp import subapp #Assumes subapp.py and associated import
app.mount('/subapp', subapp) #Assumes subapp.py and associated import

@app.route('/')
def hello():
    return 'Hello World'

app.run()

Error:

Traceback (most recent call last):
 File "example.py", line 14, in <module>
 @app.route('/')
 AttributeError: 'SessionMiddleware' object has no attribute 'route'

Is this behaviour supported by beaker? If so, can you advise what I am doing wrong here?

@amol-
Copy link
Collaborator

amol- commented Apr 5, 2015

You are wrapping app with the beaker middleare, so app is not a Bottle object anymore.
You should apply the middleware after you configured your app, not before.

See: http://bottlepy.org/docs/dev/recipes.html#keeping-track-of-sessions

@amol- amol- closed this as completed Apr 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants