gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:15:02 24 4
gpt4 key购买 nike

当我转到/home/index 时,索引路由有效

但是为什么我输入/home/test 却不起作用

这里出了什么问题,很困惑!

导入日志记录

从 pylons 导入请求、响应、 session 、tmpl_context as c、url从 pylons.controllers.util 导入中止,重定向

从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

最佳答案

仔细检查你的缩进。如果 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"

关于python - 为什么我的路线不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3695670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com