On Dec 5, 3:37 pm, Mike Orr <[email protected]> wrote:
> Ouch, that sounds like "I'm better than you but I'm not going to tell
> you why." In other words, it may or may not be true, depending on
> whatever he might be basing it on.
That's supposed to sound like "Every website on the internet follows a
certain paradigm. If you don't know why, you should be searching to
learn -- because everyone will be wasting their time trying to teach
you the right thing and you're not going to listen until you read it
elsewhere as that's how people who ask for help always act ."
In terms of "login" actions ( as referenced above ) it is absolutely
true.
Getting back to the issue...
as I said before , "render" just returns the value of the render.
the reason why the code does not work, is because the OP is not
calling return
> class AController(BaseController):
> def foo(self):
> #do stuff
> print 'in foo'
> return render("/foo.html")
>
> def bar(self):
> 'v' in request.params or self.foo() # foo should not return,
> it is calling render
> print 'what am i doing here?'
> v = request.params['v'] #attribute error if I
> visithttp://localhost/pylons/a/bar/. Why doesn't it render foo?
> #continue doing stuff
>
> However this code prints 'in foo' then 'what am I doing here?' and I think
> its because the request cycle is getting things confused (kind of jumping
> into another one before finishing first). While perhaps not a bug (but I'm
> not sure of that, it is indeterminate what will happen), it could be handled
> better and would be if I could throw out the response so far and restart with
> the new method (be more performant as well).
self.foo() does not dispatch a new request, it merely calls the foo()
method of self inline
the request cycle is not getting confused. the dispatcher called
self.bar() , and that is it. self is just a python object.
if you want to return the output of foo, the code should be
def bar(self):
if 'v' not in request.params:
return self.foo()
print 'what am i doing here?'
v= request.params['v']
#continue doing stuff
"Why doesn't it render foo?"
the original code did render foo. however it did nothing with the
output.
calling self.foo() doesn't create a new request / re-dispatch , it
just runs foo() like any other python object woud. if you want to do
that, you need to redirect or subrequest.
in order to foo() and stop and return the output of foo() to the
browser, you would call
return self.foo()
Look through my first example, and Graham's later example -- which
both addressed this pattern.
--
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.