Problem in Cherrypy. Some functions are called twice...

3 views
Skip to first unread message

Raja

unread,
Mar 3, 2008, 3:50:19 AM3/3/08
to cherrypy-devel
Hi all,
I face aproblem in cherrypy.

Following is my code.

import cherrypy
import os
from cherrypy.lib import static

class root:
def index( self ):
return '''
<HTML>
<BODY>
<FORM name=login_page action="/GreetUser/" enctype="multipart/
form-data" method="POST">
<TABLE bgcolor=lightsteelblue align=center >
<TR>
<TD colspan=2 align=middle><INPUT type="submit" value="Login"
onclick=login_page.submit() ></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>'''
index.exposed = True

def GreetUser( self ):
return '''
<HTML>
<BODY>
WELCOME...
</HTML>
</BODY>'''
GreetUser.exposed = True


rt = root()
cherrypy.tree.mount(rt)

if __name__ == '__main__':
cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'tutorial.conf'))
current_dir = os.path.dirname(os.path.abspath(__file__))
cherrypy.config.update({'environment': 'production',
'log.error_file': 'site.log',
'log.screen': True})

cherrypy.server.quickstart()
cherrypy.engine.start()

-----------------------------------------------------------------------------------------------------------------------------------------

If u want to run this code, please create a "tutorial.conf" file in
the same directory from where u run the code.

In the "tutorial.conf" file add the following contents, save it and
then run the code.

[global]
server.socket_port = 80
server.thread_pool = 10
tools.sessions.on = True

-----------------------------------------------------------------------------------------------------------------------------------------

Now, if you keep a breakpoint in "GreetUser" function and click the
login button in your browser,
you can find the "GreetUser" function being called twice. So if I want
to update database fields in this function it would be updated twice
which would lead to a crash of Application.

I don't know why it is happening...
I think I am not making any mistakes in code... am I???

Could you please tell me a solution for this?????

Regards,
Raja

Ionel Maries Cristian

unread,
Mar 3, 2008, 11:44:30 AM3/3/08
to cherryp...@googlegroups.com
you don't need a onclick handler on the submit button, and probably that's the origin of the double request
Reply all
Reply to author
Forward
0 new messages