[Twisted-web] Context Help

Tommi Virtanen tv at twistedmatrix.com
Mon Sep 12 08:17:24 MDT 2005


Michael M wrote:
> Thanks in advance for any help.
> 
> My problem is getting context to remember things.  If I remember
> something when the context is PageContext, I cannot retrieve it when
> the context changes to say WebContext because it tells me that it has
> not been remembered.
> 
> Now, I was under the impression that context would search for my
> interface through the different contexts but this does not seem to be
> the case. This kind of limits what I can do with context because I
> have no idea when the context changes and my rememberances will be
> forgotten.
> 
> Example Problem
> 
> def render_cow(self, ctx, data):
>     ctx.remember(data, ISomeInterface)
> 
> def render_something_else(self, ctx, data):
>     mydata = ctx.locate(ISomeInterface)
> 
> Now in between remebering ISomeInterface and recalling it the context
> changes and it is no longer remebered.
> 
> My apologies if I am way out with my understanding and any help is appreciated.

If your template is

	<foo n:render="cow">
	 <bar n:render="something_else />
	</foo>

that should work. If your template is

	<foo n:render="cow" />
	<bar n:render="something_else />

then it even shouldn't work (AIUI).

The context stack in the latter example is like this, as time passes:

[the page]

...

[the page]
[context for render_cow]

...

[the page]

...

[the page]
[context for render_something_else]



More information about the Twisted-web mailing list