【发布时间】:2023-03-17 21:23:01
【问题描述】:
我已经用 Bottle 编写了一些代码。这真的很简单,适合我的需要。但是,当我尝试将应用程序包装到一个类中时,我被卡住了:
import bottle
app = bottle
class App():
def __init__(self,param):
self.param = param
# Doesn't work
@app.route("/1")
def index1(self):
return("I'm 1 | self.param = %s" % self.param)
# Doesn't work
@app.route("/2")
def index2(self):
return("I'm 2")
# Works fine
@app.route("/3")
def index3():
return("I'm 3")
是否可以在 Bottle 中使用方法而不是函数?
【问题讨论】:
-
为什么不装瓶CBV github.com/techchunks/bottleCBV
标签: python oop class methods bottle