Problem passing parameters into a nested root.xyz path

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem passing parameters into a nested root.xyz path

Gloria W

Hi again,
I have another problem unrelated to my previous post.
Here's my code:

import cherrypy
import pdb
TemplatePath='./Templates'

class Login:
        def index(self):
                ft=open(TemplatePath + '/login')
                showPage=ft.read()
                ft.close()
                return showPage
        index.exposed = True

        def login_resp(self,username,password):
                return "Login: Got parameters: %s %s" %
(username,password)
        login_resp.exposed = True

class Login2:
        def index(self,username,password):
                return "Login2: Got parameters: %s %s" %
(username,password)
        index.exposed = True

if __name__ == '__main__':
        root = Login()
        root.login_resp2 = Login2()
        cherrypy.tree.mount(root)

        import os.path
        cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'default.conf'))
        cherrypy.server.quickstart()
        cherrypy.engine.start()


Here is the HTML used to access these methods:

<center>
<h3>Please log in:</h3>
<form action="login_resp" method="post">
    <br>Username
    <input type="text" name="username" value=""
        size="15" maxlength="40"/>
    <br>Password
    <input type="password" name="password" value=""
        size="10" maxlength="40"/>
    <br><input type="submit" value="Login"/>
    <br><input type="reset" value="Clear"/>
</form>
</center>


The things I'm testing are login_resp, and login_resp2. Notice the
nesting, and how login_resp class, Login(), is what root is intialized
to use.  login_resp2 is a separate class, initialized as
root.login_resp2.

In my FORM, my action is set to login_resp, and things work fine:

Login: Got parameters: test hkjkh

 If I then change my FORM action to login_resp2, refresh, and send the
exact same parameters, I get this:

Traceback (most recent call last):
  File
"/usr/local/python/2.5/lib/python2.5/site-packages/cherrypy/_cprequest.py",
line 539, in respond
    cherrypy.response.body = self.handler()
  File
"/usr/local/python/2.5/lib/python2.5/site-packages/cherrypy/_cprequest.py",
line 110, in __call__
    return self.callable(*self.args, **self.kwargs)
TypeError: index() takes exactly 3 arguments (1 given)

The correct method in the correct class is being called, but the
parameters from the FORM  are not being passed into the
root.login_resp2 class. Why is this happening?

Thank you,
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem passing parameters into a nested root.xyz path

Robert Brewer
Gloria wrote:
> If I then change my FORM action to login_resp2,
> refresh, and send the exact same parameters,
> I get this:
> TypeError: index() takes exactly 3 arguments (1 given)
>
> The correct method in the correct class is being called,
> but the parameters from the FORM  are not being passed
> into the root.login_resp2 class. Why is this happening?

You're probably getting redirected from login_resp2 to login_resp2/ (note trailing slash). And POST redirects aren't supposed to re-pass parameters without asking the user's permission. Try adding the trailing slash to the form action. Other ways to fix it would be 1) move the login_resp2 handler to a non-index method, 2) set tools.trailing_slash.missing to False, 3) find a browser that allows resubmission of params on 302/303 redirects. ;)


Robert Brewer
System Architect
Amor Ministries
[hidden email]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

winmail.dat (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem passing parameters into a nested root.xyz path

Gloria W

Ahh..ok. The redirection from non-slash to an ending slash was not
obvious to me at all. This makes sense.
I chose option (2) for now instead of (1), although I think (1) is the
better way in the long run. It works well.

It's so nice to post to a developer's list and get useful, appropriate
responses. :)

Thank you once again.
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---