为什么我的路线不起作用?

时间:2010-09-12 16:49:23

标签: python pylons

当我转到/ 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

1 个答案:

答案 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"