Re: configuring a response on a request
Tim Roberts <[email protected]>
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Organization | Providenza & Boekelheide, Inc. |
| Message-ID | <[email protected]> |
matt Gerwen van wrote:
>
> I am very new to programming and cherrypy.
> So far I understand that a method of a class, which has been exposed,
> is a page handler ( =becomes a html page). How do I tell cherrypy to
> come back, response with page-x?
Part of this is understanding the flow of a web server. Think about
things from a "flow" point of view, and perhaps it will make more sense.
So, you might have a login page, http://mysite/login, which displays a
login page, and say that a logged-in user has to go to a main. When the
user responds, it's up to you to decide whether the <form> goes to your
"login" handler or to your "main" handler for validation. Usually, I
want the response to page "x" to be handled by the page "x" handler.
But in that case, if the "login" handler approves the login, then you
need to show the "main" page. In my view, the most expedient method of
doing that is to send a redirect. Your login pages raises an
HTTPRedirect exception with the next URL. The browser, in response,
will make a new request. So:
def login(self, user, pass):
if validate(user,pass):
cherrypy.session[xxx] = user
raise cherrypy.HTTPRedirect('/main')
else:
tmplt.error = "Invalid Login"
Go display template
--
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.