Hi Diez,
thanks for your email. You're correct I was using an invalid context
object. After fixing the bug, I was able to display the tree properly.
I have another question regarding to generating the tree dynamically.
Instead of having navTree div defined statically in the template (as in TG
tutorial example), I have a python xml string object (mytext) in my
controller (root.py). This string can potentially be created dynamically,
but for now i have it predefined. I pass this string to the template
(about.html). For some reasons, it does not seem to work as the way I
expected. My browser just shows the actual text of "mytext", but not a
tree. Any suggestion for me to try? Below are code from my root.py and
about.html. Thanks much.
@expose('helloworld.templates.about')
def about(self, **kw):
myTree = TreeView(treeDiv='navTree')
pylons.c.tree = myTree
mytext =""" <ul>
<li class=\"open\"> product123
<ul>
<li class=\"open\"> level1
<ul>
<li class=\"open\" id=\"a\">
format=a
<ul>
<li class=\"open\"
id=\"convert\"> step=convert
<ul>
<li>item1</li>
<li>item2</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul> """
return dict(mytext=mytext)
about.html:
========
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="master.html" />
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<title>Welcome</title>
</head>
<body>
${tmpl_context.tree()}
<div id="navTree">
<ul py:content="mytext"> replace this </ul>
</div>
</body>
</html>
On Thu, Nov 12, 2009 at 3:10 AM, Diez B. Roggisch <[email protected]> wrote:
>
> tpnguyen schrieb:
> > Hi,
> >
> > I tried to use the TurboGears 2 TreeView example , but I got the error
> > below:
> >
> > UndefinedError: <pylons.util.ContextObj at 0x268b770
> > action=u'routes_placeholder', controller=u'root', controller_url='',
> > environ={'routes.route': <routes.route.Route object at
> > 0x00EB2550>, ...ate'}, form_errors={}, form_values={}, identity=None,
> > pylons=<pylons.util.PylonsContext object at 0x0268B7D0>,
> > start_response=<function repl_start_response at 0x02674670>,
> > url=u'about'> has no member named "tree"
> >
> > Looks like tmpl_context has no member named "tree". Am I missing
> > anything here? Please shed a light on how to debug this? Thanks much
> > in advance.
>
> I don't know pylons that well, but to me, the tmpl_context always
> behaved like this: if a key wasn't existant, it returned an empty string
> (somebody said PHP here?).
>
> So I'd expect your error to be "AttributeError: string-object has no
> attribute display".
>
> That might indicate that you are using the wrong context object here?
> Just guessing - I never imported the context from pylons, instead via tg.
>
> from tg import tmpl_context as c
>
> Diez
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---