The 'context' that keeps on popping up (Request context, Snakelet context, Session context, Application context) is just a simple holder for any value you like. It is an 'empty' object that you can add your own attributes to, for instance:
self.getAppContext().userName = req.getParameter("userName")
And in your pages you can access them easily, for instance:
<h1>Hello, <%=ApplicationCtx.userName%>!</h1>
You have to use the ContextContainers to store information! It is not a good idea to store your data directly in the Snakelet, Webapp or whatever other objects!
TIP: to avoid AttributeError exceptions when you're accessing attributes that have not been defined in the context, you can use getattr with a default parameter:
<h1>Hello, <%=getattr(ApplicationCtx,"userName","unknown name")%>!</h1>
TIP: the Application context is perfectly suited to store stuff that you want to have access to (from your Ypages/snakelets) during the whole application, such as utility classes or persistent variables. You can do this in the __init__ method of one of your snakelets, for instance. The Session context is very important: you can store stuff here that is associated with the user session (it is unique per user, and is removed when the user is no longer on the site).
The Request context is volatile and only exists during the processing of a single request. You can put values here that need to be displayed on the target page.
The Snakelet context is not very useful (its inside a single snakelet, you could use regular class attributes for the same purpose).
The WebApp runs inside the server. You cannot access this server. This is due to security restrictions, and most interesting stuff is already accessible trough the other interfaces). Because of this, the 'largest' scope is the web app scope. You cannot exchange information with another web app by using context storage, for example. You can store things on the web app context and read them from other snakelets or Ypages, within the same webapp.
Snakelets manual - Back to index