Re: Modifying a page and not creating a new one
Tim Roberts <[email protected]>
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Organization | Providenza & Boekelheide, Inc. |
| Message-ID | <[email protected]> |
Denis LE FUR wrote:
> Hello, I am a new user...
>
> Here is an example. The result appears in a new page. How to put it in
> the index page ?
To start, you need to change the <form> tag so that action="index".
Now you need some way to tell whether you're being called to display the
blank page, or to display the results. You can do that by assigning a
name to your "submit" button. Then you can check that value in the
code. If it is present, then you are being asked to compute. If not,
then it is an initial display. For example:
def index(self, a=0, b=0, btn=None):
s = ""
if btn:
# We were asked to do a computation.
r = int(a)+int(b)
s += "<p>Result of %d + %d is %d" % (a, b, r)
s += """
<form action='index' method='GET'>
<input type=number name='a'> +
<input type=number name='b'>
<input type=submit name=btn value='='>
</form>
"""
return s
The next exercise for you is to change the code so that the "a" and "b"
fields on the form show the previous values.
--
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
--
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-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.