我是新來的Python和水泥應用,對象在蟒蛇水泥沒有屬性_meta應用
我只是通過在水泥應用程序提供的文檔會和我面臨着以下問題
Traceback (most recent call last):
File "/Users/Amith/python/learning/inter.py", line 80, in <module>
app.handler.register(MyHandler)
File "/Users/Amith/python/learning/connectors/lib/python2.7/site-packages/cement/core/handler.py", line 195, in register
if not hasattr(obj._meta, 'label') or not obj._meta.label:
AttributeError: 'MyHandler' object has no attribute '_meta'
我沒有從文檔中找到很多幫助,也沒有驗證其他幾個網站。
請在下面找到
from cement.core.foundation import CementApp
from cement.core.interface import Interface, Attribute
from cement.core import interface
from cement.core.handler import CementBaseHandler
def my_validator(klass, obj):
members = [
'_setup',
'do_something',
'my_var',
]
interface.validate(MyInterface, obj, members)
class MyInterface(Interface):
class IMeta:
label = 'myinterface'
validator = my_validator
# Must be provided by the implementation
Meta = Attribute('Handler Meta-data')
my_var = Attribute('A variable of epic proportions.')
def _setup(app_obj):
""" The setup function """
def do_something():
""" This function does something. """
class MyHandler(CementBaseHandler):
class Meta:
interface = MyInterface
label = 'my_handler'
description = 'This handler implements MyInterface'
config_defaults = dict(
foo='bar'
)
my_var = 'This is my var'
def __init__(self):
self.app = None
def _setup(self, app_obj):
self.app = app_obj
def do_something(self):
print "Doing work!"
class MyApp(CementApp):
class Meta:
label = 'myapp'
define_handlers = [MyInterface]
handlers = [MyHandler]
app = CementApp('myapp')
# define interfaces after app is created
app.setup()
print app.config.keys('myapp')
app.config.set('myapp', 'debug', True)
print app.config.keys('myapp')
app.handler.define(MyInterface)
app.handler.register(MyHandler)
app.run()
我的代碼任何幫助將大大appriciated
從http://builtoncement.com/2.10/dev/interfaces_and_handlers.html – amith