On Dec 4, 3:43 pm, John_Nowlan <[email protected]> wrote:

> Why can't I do the (simplified) following?

probably because you shouldn't be doing it.

> i.e. I'd like to transfer control to another method (self.login) from self.bar

that's a really awkward, and bad, idea.  its proper form to redirect
someone to the login page.

    if 'logged_in' not in session or not session['logged_in']:
        redirect_to (/login)

I'm not going to waste time describing why you should  be doing
that.   everyone on the internet follows that paradigm for a reason.

> I think I sort of understand whats happening (I get to 'what am I doing 
> here?' when self.login returns, but shouldn't the render terminate things? Or 
> is there a safe way to handle this? I seem to remember (don't laugh) ms asp 
> had a request.transfer function or something that allowed you to terminate a 
> request and transfer to another function. I find this a natural way to 
> express things and would like to be able to do this without redirecting (i.e. 
> no trip back to client).

render() is a function in the templating system.  it simply accepts a
template file location, and returns that template rendered with the C
data and misc control logic.

when you see in a controller:
    return render(/path)

then you are returning ( to the browser ) the output of render.

you could have this as a controller:

class AccountLoginStatusController(BaseController):

    def logged_in(self):
         return "You are logged in.  Click here to continue: /my/home"

    def logged_out(self):
         return "You are not logged in.  Click here to login: /my/
login"

    def index(self):
        if 'logged_in' not in session or not session['logged_in']:
            return self.logged_out()
        return self.logged_in()

As a technical answer, your line

    self.login

should be:

    self.login()

if the login() function is merely a setup/convenience function.
calling it like this,however, will just run that function in place,
and the controller will continue.

if you want to return the output of login and stop processing, ie show
the login form, the line would be:
    return self.login()

However, as a user experience answer, your line should read

    redirect( "/login")

--

You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.


Reply via email to