我有几个类似的 python cherrypy 应用程序
application_one.py
import cherrypy
class Class(object):
@cherrypy.tools.jinja(a='a', b='b')
@cherrypy.expose
def index(self):
return {
'c': 'c'
}
application_two.py
import cherrypy
class Class(object):
@cherrypy.tools.jinja(a='a2', b='b2')
@cherrypy.expose
def index(self):
return {
'c': 'c2'
}
……
应用程序_n.py
import cherrypy
class Class(object):
@cherrypy.tools.jinja(a='aN', b='bN')
@cherrypy.expose
def index(self):
return {
'c': 'cN'
}
我想创建父类并在所有应用程序中派生它。像这样的东西
父.py
import cherrypy
class ParentClass(object):
_a = None
_b = None
_c = None
@cherrypy.tools.jinja(a=self._a, b=self._b)
@cherrypy.expose
def index(self):
return {
'c': self._c
}
application_one.py
import parent
class Class(ParentClass):
_a = 'a'
_b = 'b'
_c = 'c'
application_two.py
import parent
class Class(ParentClass):
_a = 'a2'
_b = 'b2'
_c = 'c2'
如何从派生类发送索引方法装饰器的参数?
现在我得到错误
NameError:名称“自我”未定义