Re:Why should bottlepy stick to a file?
by rambojazz on Sunday January 12, 2020 @01:03AM
(#22024751)
wsgi is an interface; if you implement it then you are compatible. The simplest way is to just use another Bottle app, or maybe subclass the Bottle class like this `class MyClass (Bottle):`, otherwise you can create a new class by implementing the interface methods (many tutorials online for this). Then you "mount" that wsgi object into a specific path using the `.mount()` function of your main Bottle app.
[ Parent
| on HN ]
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?
Re:Why should bottlepy stick to a file?
by rambojazz on Sunday January 12, 2020 @03:29PM
(#22029071)
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 testYou should have 2 working routes, "/" and "/hello/<name>".