pagehandler not run

27 views
Skip to first unread message

yy

unread,
Sep 21, 2008, 11:24:52 PM9/21/08
to cherrypy-users
I refer to document write pagehandler wrapper in tut01_helloworld.py
but it's not run right.
I think at least it ought print 'my wrapper handle', but not happen.
so why?

code:

"""
Tutorial - Hello World

The most basic (working) CherryPy application possible.
"""

# Import CherryPy global namespace
import cherrypy

class HelloWorld:
""" Sample request handler class. """

_cp_config = {'tools.sessions.on': True}
def index(self):
# CherryPy will call this method for the root URI ("/") and
send
# its return value to the client. Because this is tutorial
# lesson number 01, we'll just send something really simple.
# How about...
return "Hello world!"

# Expose the index method through the web. CherryPy will never
# publish methods that don't have the exposed attribute set to
True.
index.exposed = True


import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')

to_skip = (KeyboardInterrupt, cherrypy.HTTPRedirect)
def myWrapper(next_handler, *args, **kwargs):
print 'my wrapper handle'
cherrypy.session['my_ip_address'] = 'ok'
result = next_handler(*args, **kwargs)
return result
cherrypy.tools.pgsql = cherrypy._cptools.HandlerWrapperTool(myWrapper)

if __name__ == '__main__':
# CherryPy always starts with app.root when trying to map request
URIs
# to objects, so we need to mount a request handler root. A
request
# to '/' will be mapped to HelloWorld().index().
cherrypy.quickstart(HelloWorld(), config=tutconf)
else:
# This branch is for the test suite; you can ignore it.
cherrypy.tree.mount(HelloWorld(), config=tutconf)

Robert Brewer

unread,
Sep 27, 2008, 1:29:30 AM9/27/08
to cherryp...@googlegroups.com
yy wrote:
> I refer to document write pagehandler wrapper in tut01_helloworld.py
> but it's not run right.
> I think at least it ought print 'my wrapper handle', but not happen.
> so why?

Below, you've created the 'pgsql' tool but you haven't "turned it on"
for any URL's. Try changing the _cp_config to:

_cp_config = {'tools.sessions.on': True,
'tools.pgsql.on': True}

You can also turn on your tool in a config file, or with a decorator, as
described at http://www.cherrypy.org/wiki/BuiltinTools#Usingtools


Robert Brewer
fuma...@aminus.org

yy

unread,
Oct 2, 2008, 8:59:00 AM10/2/08
to cherrypy-users
It is right,
thank you!

On 9月27日, 下午1时29分, "Robert Brewer" <fuman...@aminus.org> wrote:
> yy wrote:
> > I refer to document write pagehandler wrapper in tut01_helloworld.py
> > but it's not run right.
> > I think at least it ought print 'my wrapper handle', but not happen.
> > so why?
>
> Below, you've created the 'pgsql' tool but you haven't "turned it on"
> for any URL's. Try changing the _cp_config to:
>
> _cp_config = {'tools.sessions.on': True,
> 'tools.pgsql.on': True}
>
> You can also turn on your tool in a config file, or with a decorator, as
> described athttp://www.cherrypy.org/wiki/BuiltinTools#Usingtools
> fuman...@aminus.org- 隐藏被引用文字 -
>
> - 显示引用的文字 -
Reply all
Reply to author
Forward
0 new messages