Form handler 404

31 views
Skip to first unread message

Jack Eisenbach

unread,
Apr 7, 2020, 12:35:47 PM4/7/20
to cherrypy-users
I have a registration form and it should get processed by a function called register_handler() but when the Submit button is pressed, it tries to get to
/register/register_handler() instead of register_handler() which results in a 404 error.

The code:

    @cherrypy.expose
    def register(self):

        html = self.get_head('Register')
        html += ' </head> <body> <br>'
        html += ' <h1 align="center" > Register <h5>'
        html += ' <br> <a href="http:/home/"> home </a> '
        html += ' <a href="http:/about/"> about </a>  <br>'
        html += ' <a href="http:/contact/"> contact </a>  <br>'
        html += '''<p>
                    </p><table style="border: 1px solid black;">
                    <form action="register_handler" method="post">
                    <trstyle="border: 1px solid black;">
                    <trstyle="border: 1px solid black;"><tr><td align="left"><th align="left">Firstname:</th></td><td><input name="firstname" type="text" value="John"></input></td></tr>
                    <trstyle="border: 1px solid black;"><tr><td align="left"><th  align="left">Lastname:</th></td><td><input name="lastname" type="text" value="Doe"></input></td></tr>
                    <trstyle="border: 1px solid black;"><tr><td align="left"><th align="left">Email:</th></td><td><input name="email" type="text" value="elme...@gmail.com"></input></td></tr>
                    <trstyle="border: 1px solid black;"><tr><td></td><td><th align="center"><input type="submit">Submit!</button></input></td><td></td></tr>
                    <trstyle="border: 1px solid black;"><tr><td align="left"><th align="left">Password:</th></td><td><input name="password" type="text" value=""></input></td></tr>
                    </form>
                    </table>
                    </body></html> '''

        html += ' </html> '
        return html

        """ The function below handles the register form processing of the above register function."""
    @cherrypy.expose
    def register_handler(self, Firstname = "John", lastname= 'Doe', email='joh...@gmail.com'):

        print "inside register_handler routine"
        cherrypy.log("inside register_handler function")
        html = self.get_head()
        html += self.get_header_links('register')
        print  "Firstname:", firstname
        print  "Lastname:", lastname
        print  "Email:", email
        print  "Password:", password
        raise  cherrypy.HTTPRedirect(cherrypy.url('.'))
#        @cherrypy.expose
#        def contact(self):
AccessLog:
127.0.0.1 - - [17/Mar/2020:11:34:09] "GET /register/register_handler?firstname=John&lastname=Doe&email=elmerfudd%40gmail.com&password=Homerhead HTTP/1.1" 404 1161 "http://127.0.0.1:8080/register/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"
I am not sure how to remove the leading /register/ that gets prepended to the register_handler URL so it results in a 404 and the register_handler function never gets called.

TIA if someone can point to what I need to do to correct this!

Jack

Joel Rivera

unread,
Apr 7, 2020, 1:32:40 PM4/7/20
to cherryp...@googlegroups.com
Hi Jack,

the problem is in the HTML form that you are generating.

Given your current setup, you could use an absolute path, change:

           <form action="register_handler" method="post">

to
           <form action="/register_handler" method="post">


The slash is the key.
--
Joel Rivera
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.

Jack Eisenbach

unread,
Apr 7, 2020, 2:27:50 PM4/7/20
to cherrypy-users
Thanks much Joel!!! That was it.
Kind regards,
Jack

Jack Eisenbach

unread,
Apr 7, 2020, 2:34:18 PM4/7/20
to cherrypy-users
Thanks much Joel!!! That was it.
Kind regards,
Jack

On Tuesday, April 7, 2020 at 9:35:47 AM UTC-7, Jack Eisenbach wrote:
Reply all
Reply to author
Forward
0 new messages