Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Right, I get that part (sort of).

But looking at the quickstart, you typically don't subclass Bottle, you require it, and call run()? So your typical bottle app won't be a subclass of bottle? At which point you can't make an instance of it, to pass to mount()?

Looking at the documentation for mount() it looks like you should be able to mount the quick-start app - but it's not clear of you create an instance to pass to mount?

That is if I have example.py:

  from bottle import route, run, template

  @route('/hello/<name>')
  def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

  run(host='localhost', port=8080)
How do I write example_mount.py that mounts example.py under /hello1 and /hello2?


    test.py
    =======
    import bottle
    
    @bottle.get('/')
    def index():
        return 'INDEX'
    
    # a new wsgi app
    hello = bottle.Bottle()
    
    @hello.get('/<name>')
    def greet(name):
        return 'Hello, ' + name
    
    bottle.app().mount('/hello', hello)
Test like this: python3 -m bottle --bind :8080 test

You should have 2 working routes, "/" and "/hello/<name>".


Thanks, that makes sense.

But I'm still not clear on how I require "example.py" and mount it (ie how do I make an wsgi instance from a python file that is a bottle app)?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: