bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.38k stars 1.46k forks source link

No access to system-wide app.config in mounted sub-app #964

Open pyx opened 7 years ago

pyx commented 7 years ago

Consider:

from bottle import Bottle, request

child = Bottle()

@child.get('/')
def c_index():
    # http://127.0.0.1:8080/c/
    # this will fail, undefined 'secret_key'
    return request.app.config['secret_key']

def create_app():
    app = Bottle()

    @app.get('/')
    def index():
        # http://127.0.0.1:8080/
        # showing: 'oh my'
        return request.app.config['secret_key']

    app.config['secret_key'] = 'oh my'

    app.mount('/c/', child)

    return app

if __name__ == '__main__':
    app = create_app()
    app.run(debug=True)

http://127.0.0.1:8080/ showing 'oh my', and http://127.0.0.1:8080/c/ will be 500, replacing request.app with bottle.default_app() did not work, too.

Is it by design? If so, what is the preferred way to read configuration in mounted applications without hacks? Thanks.

pyx commented 7 years ago

UPDATE: 2017-04-17

Upon further investigation, I deleted then re-created the virtualenv, and it worked as expected, guess something dumb on my part, sorry about that. I will close this now.

pyx commented 7 years ago

UPDATE2:

I did mess up again.

It did not work with the latest version on PyPI (0.12.13)

It worked with master (as of rev. 41ed696) on github.

So, I can't wait to use version 0.13 then, mounting with prefix is a must for what I am doing, it's been blocking me months now.

pepelisu commented 7 years ago

The mounting functionality as you said in only supported in 0.13-dev (master). This version is still under development and has not been release. If you want to use version 0.13, I recommend to clone (or download the master branch from the repo). I am using it regularly without much problems.