当我转到/ home / index
时,索引路由有效但是为什么我输入/ home / test
它不起作用这里有什么问题,非常困惑!
导入日志记录
从pylons导入请求,响应,会话,tmpl_context为c,url 来自pylons.controllers.util import abort,redirect
来自helloworld.lib.base导入BaseController,渲染
log = logging.getLogger(名称)
类HelloController(BaseController):
def index(self):
# Return a rendered template
#return render('/hello.mako')
# or, return a string
return 'Hello World from index() action!'
def test(self):
return 'blah'
我收到此错误:
WebError Traceback:
⇝ NotImplementedError: Action u'test' is not implemented
View as: Interactive | Text | XML (full)
URL: http://127.0.0.1:5000/hello/test
Module weberror.evalexception:431 in respond view
>> app_iter = self.application(environ, detect_start_response)
Module beaker.middleware:152 in __call__ view
>> return self.wrap_app(environ, session_start_response)
Module routes.middleware:131 in __call__ view
>> response = self.app(environ, start_response)
Module pylons.wsgiapp:107 in __call__ view
>> response = self.dispatch(controller, environ, start_response)
Module pylons.wsgiapp:312 in dispatch view
>> return controller(environ, start_response)
Module helloworld.lib.base:15 in __call__ view
>> return WSGIController.__call__(self, environ, start_response)
Module pylons.controllers.core:211 in __call__ view
>> response = self._dispatch_call()
Module pylons.controllers.core:168 in _dispatch_call view
>> action)
NotImplementedError: Action u'test' is not implemented
答案 0 :(得分:2)
仔细检查缩进。如果def test(self)与类的缩进级别相同,则不会出现缩进错误。
这会引发缩进错误:
class HelloController(BaseController):
def index(self):
return "hello from index()"
def test(self):
return "blah"
这不是:
class HelloController(BaseController):
def index(self):
return "hello from index()"
def test(self):
return "blah"