_cp_dispatch没有在cherrypy中被调用 [英] _cp_dispatch not getting called in cherrypy
问题描述
在以下示例中,我希望访问url http://127.0.0.1时会出现异常:8080/b/method_b .相反,我在浏览器中收到包含文本"method_b"的正常http响应.没有引发异常,这意味着不调用_cp_dispatcher._cp_dispatch出现问题了吗?我在python 2.7.10中使用cherrypy版本3.8.0
In the following example, I would expect to get an exception when accessing url http://127.0.0.1:8080/b/method_b. Instead, I get normal http response containing text 'method_b' in browser. No exception raised, meaning that _cp_dispatcher is not called. Am I getting something wrong about _cp_dispatch? I am using cherrypy version 3.8.0 in python 2.7.10
import cherrypy
class B(object):
def _cp_dispatch(self, vpath):
raise Exception("Here!!")
@cherrypy.expose
def method_b(self):
return "method_b"
class A(object):
def __init__(self):
self.b = B()
cherrypy.quickstart(A())
推荐答案
是的,您在 _cp_dispatch
方面遇到了一些问题,只有在没有属性/方法与请求匹配时才会调用它.
Yes you're getting something wrong about _cp_dispatch
it will only be called when no property/method matches the request.
如果您拨打以下电话,则会引发异常: http://127.0.0.1:8080/b/method_a.
It will raise the exception if you call: http://127.0.0.1:8080/b/method_a.
method_a
不存在, method_b
存在.
这篇关于_cp_dispatch没有在cherrypy中被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!