Answer the question
In order to leave comments, you need to log in
How to use a class method instead of a function in the Bottle microframework?
In general, what I want is to substitute the route decorator
@route('/hello')
test.test_method()
from bottle import route, run
class test():
def g_test(self):
return "<h1> Hello from test method! </h1>"
t = test()
@route('/test')
t.g_test()
run(host='localhost', port=8080)
from bottle import route, run, template
class test():
@route('/hello')
def getRes(self=None):
return "<h1> Hello from test method! </h1>"
t = test()
run(host='localhost', port=8080,debug=True)
app.route('/', method='GET', callback=t.getRes())
@route('/test')
def view():
t = test()
return t.getRes()
Answer the question
In order to leave comments, you need to log in
What's the problem with doing
t = test()
@route('/test')
def test():
return t.getRes()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question