How to replace ElementTree

39 views
Skip to first unread message

Remi Jolin

unread,
Sep 28, 2012, 11:47:42 AM9/28/12
to turbo...@googlegroups.com
Hello,

Still trying to get my marks with TG2.2 :-)

With TG1/genshi when I wanted to include some html pieces dynamically
generated is used ElementTree
for example :
upd_link = ET.Element('a', href='/xxx/%s' % value)
upd_link.text = 'some text'

and I passed this value in the returned dict.

In genshi I simply add something like
<a py:replace="upd_link">place holder</a>

Now I tried to do the same with TG2.2 and jinja ({{ upd_link }}) but I
can't get anything displayed (no error, but nothing generated).

So how can I get the same result I had with TG1 ?

Mengu

unread,
Sep 28, 2012, 2:50:55 PM9/28/12
to turbo...@googlegroups.com
hi remi,

is there any special reason building the html element with element tree? you certainly can use the value in your template.

<a href="{{ upd_link }}">update</a>

Remi Jolin

unread,
Sep 28, 2012, 3:12:06 PM9/28/12
to turbo...@googlegroups.com
I think it is because TG1/genshi has autoescaping enabled and I have
enabled autoescape in jinja too.
ET is also a convenient way to build html structures when things get a
bit more complicated :-)

By the way, I found a solution with a custom filter, so I can write
something like <a href="{{ upd_link|et }}">update</a>

Le 28/09/2012 20:50, Mengu a �crit :
> --
> You received this message because you are subscribed to the Google
> Groups "TurboGears" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/turbogears/-/v-nJZb4YLJ8J.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to
> turbogears+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.

Mengu

unread,
Sep 28, 2012, 6:30:11 PM9/28/12
to turbo...@googlegroups.com
you totally don't need that filter.

in your controller action pass the upd_link variable in your dict, so it's like this:

    def my_action(self):
        upd_link = "/some/link/%s" % value
        return dict(upd_link=upd_link)

and in your template you just do <a href="{{ upd_link }}">update</a>.

that is really just all. you don't need anything else.


On Friday, September 28, 2012 10:12:28 PM UTC+3, Remi Jolin wrote:
I think it is because TG1/genshi has autoescaping enabled and I have
enabled autoescape in jinja too.
ET is also a convenient way to build html structures when things get a
bit more complicated :-)

By the way, I found a solution with a custom filter, so I can write
something like <a href="{{ upd_link|et }}">update</a>

Le 28/09/2012 20:50, Mengu a �crit :

Remi Jolin

unread,
Sep 29, 2012, 5:48:07 AM9/29/12
to turbo...@googlegroups.com
Yes, I know this is a solution, but the example I gave is not really
representative of what I want to display, and, in a process of migrating
some applications from TG1 to TG2, I want to do minimal changes :-)

Le 29/09/2012 00:30, Mengu a �crit :
> you totally don't need that filter.
>
> in your controller action pass the upd_link variable in your dict, so
> it's like this:
>
> def my_action(self):
> upd_link = "/some/link/%s" % value
> return dict(upd_link=upd_link)
>
> and in your template you just do <a href="{{ upd_link }}">update</a>.
>
> that is really just all. you don't need anything else.
>
> On Friday, September 28, 2012 10:12:28 PM UTC+3, Remi Jolin wrote:
>
> I think it is because TG1/genshi has autoescaping enabled and I have
> enabled autoescape in jinja too.
> ET is also a convenient way to build html structures when things
> get a
> bit more complicated :-)
>
> By the way, I found a solution with a custom filter, so I can write
> something like <a href="{{ upd_link|et }}">update</a>
>
> Le 28/09/2012 20:50, Mengu a �crit :
> <https://groups.google.com/d/msg/turbogears/-/v-nJZb4YLJ8J>.
> > To post to this group, send email to turbo...@googlegroups.com
> <javascript:>.
> > To unsubscribe from this group, send email to
> > turbogears+...@googlegroups.com <javascript:>.
> > For more options, visit this group at
> > http://groups.google.com/group/turbogears?hl=en
> <http://groups.google.com/group/turbogears?hl=en>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "TurboGears" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/turbogears/-/NOImcsxIkKgJ.
Reply all
Reply to author
Forward
0 new messages