On Dec 7, 2011, at 7:56 PM, H.T. Wei wrote:

> Hi,
> 
> I am a newbie to Pyramid and have a question about passing variable between 
> callable like this one:
> 
>   def callable_a(request):
>      id = 1
>      ...
>      return dict( ... )
> 
>   def callable_b(request):
>      # get id from callable_a
>     
> Is there a best way for getting 'id' defined in "callable_a" in "callable_b"? 
> Any example or document?
> 
> Thanks,
> 
> HT


What you are trying to do is to save some information or "state" from one web 
page to another. At the core, web applications are stateless.  Basically, once 
callable_a has completed and a web page has been returned, the Pyramid app goes 
away and starts up again when a new request is received.  Unless you 
specifically do something, the new instance of the Pyramid app knows nothing 
about the previous one.


There are several ways to work around this and handle state.  Look at the 
pyramid.session package. This saves state in a cookie on the user's machine. If 
you are using a database with specific information for each user, you can save 
the state in the user's record in the database.  You could also store the 
information in a field, perhaps a hidden field on the form generated by 
callable_a and process that field in callable_b.

Mark


-- 
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