-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 5 Dec 2009, at 00:38, John_Nowlan wrote:
> return render("/foo.html")
>
> # foo should not return, it is calling render
No, render doesn't work like that, it works like this:
def spurious_example():
output_collector = render("header.html")
output_collector += render("body.html")
return output_collector # complete page of HTML
In your example, foo() is defined to return the result of rendering
the template which is then promptly discarded in bar() - but foo() is
nevertheless executed and so is bar(), that's why you're seeing both
printed telltales.
If foo() is intended never to appear in a URL, then either move it out
of the AController class if it is effectively a standalone support
function ...
def foo():
#do stuff
log.debug('in foo')
return render("/foo.html") # returns a string
or, if it has to be a controller method, prefix it with an underscore
which is Pylons convention for "don't expose this action".
class AController(BaseController):
def _foo():
#do stuff
log.debug('in _foo')
return render("/foo.html") # returns a string
def bar(self):
if not 'v' in request.params:
return _foo() # or save the result, whatever
else:
v = request.params['v']
log.debug('i was routed here explicitly')
#continue doing stuff
return stuff # whatever - but it must be
# an iterable
but actually, this would be the more usual approach ...
class AController(BaseController):
def _foo():
#do stuff
log.debug('in _foo')
return render("/foo.html") # returns a string
def bar(self, v=None):
if not v:
return _foo()
log.debug('hoorah, we have a v')
#continue doing stuff
return stuff # whatever - but bar /must/ return
# something that can be iterated over
With a URL of "http://localhost/pylons/a/bar/12" and a routes map of
map.connect('bar_it', '/pylons/a/bar/{v}', controller='a', action='bar)
when bar() is called via that URL, Pylons will set the value of the
keyword parameter v to 12, so you can use it directly in your action,
no need to fish it out of the dict yourself. (Best to check first that
it really is a positive integer / map reference / word, whatever.)
HTH
Cheers,
Graham
http://www.linkedin.com/in/ghiggins
-----BEGIN PGP SIGNATURE-----
iEYEARECAAYFAksZ2UAACgkQOsmLt1NhivyQOgCg6fksraHztOxj/BpLRrwbXLsc
UhEAn0wtGuC9mhSa2bacHP9A/Lrkiw0OiQCVAgUBSxnZQFnrWVZ7aXD1AQLmfgP/
csnD4JpVx8P1mkpho0VqhPeJsYP+4xxXkd3WPQ/PmM+ttZ87tn6W7Q/w/vDpceJO
wzcO+BU1GqsSHI0ZmZGf5pmLQgZYlaP4JAXstESDmRuSD4D6mFlomzZ/cy47qLBt
XkFvB4lgq0T8TMzpgw4m3++saoMLAUgLRBXk/SjePSE=
=gPka
-----END PGP SIGNATURE-----
--
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.