librelist archives

« back to archive

Wrong expactation using Markup()?

Wrong expactation using Markup()?

From:
Ben Zimmer
Date:
2010-08-17 @ 08:40
Hi,

I'm trying to inject HTML into my templates like this:

    content = Markup(rst_to_html(content))
    return render_template('show.html', content=content)

and then
<htmlblah>
{{ content }}
</htmlblah>

It's like the Markdown-snippet (http://flask.pocoo.org/snippets/19/)
but using rst.
Problem is, that I still have to things like

{{ content|safe }} or {% autoescape false %} {{ content }} {% endautoescape %}

to get the unescaped, formatted output.

Am I doing something wrong, or are just my expactations regarding
Markup() wrong?

Regards,
Ben

Re: Wrong expactation using Markup()?

From:
Ben Zimmer
Date:
2010-08-17 @ 09:08
Hmm, problem kind of solved.

Problem was I read the content from a couchdb (ViewResults)-object and
wrote it back in there.
The Markup() object somehow gets lost when writing back. When I
transfer the data to a new dict after using Markup() everything is
fine.

If someone had an explanation why the Markup() gets lost, I'd be
really willing to hear it :)

Ben

On Tue, Aug 17, 2010 at 10:40, Ben Zimmer <zeroathome@gmail.com> wrote:
> Hi,
>
> I'm trying to inject HTML into my templates like this:
>
>    content = Markup(rst_to_html(content))
>    return render_template('show.html', content=content)
>
> and then
> <htmlblah>
> {{ content }}
> </htmlblah>
>
> It's like the Markdown-snippet (http://flask.pocoo.org/snippets/19/)
> but using rst.
> Problem is, that I still have to things like
>
> {{ content|safe }} or {% autoescape false %} {{ content }} {% endautoescape %}
>
> to get the unescaped, formatted output.
>
> Am I doing something wrong, or are just my expactations regarding
> Markup() wrong?
>
> Regards,
> Ben
>

Re: [flask] Re: Wrong expactation using Markup()?

From:
Armin Ronacher
Date:
2010-08-17 @ 09:11
Hi,

On 8/17/10 11:08 AM, Ben Zimmer wrote:
> If someone had an explanation why the Markup() gets lost, I'd be
> really willing to hear it :)
CouchDB uses JSON for transfer and can only transport certain objects. 
Markup itself is an unicode string and a json encoder will silently 
convert it into a unicode string.


Regards,
Armin

Re: [flask] Re: Wrong expactation using Markup()?

From:
Ben Zimmer
Date:
2010-08-17 @ 09:23
On Tue, Aug 17, 2010 at 11:11, Armin Ronacher
<armin.ronacher@active-4.com> wrote:
> CouchDB uses JSON for transfer and can only transport certain objects.
> Markup itself is an unicode string and a json encoder will silently
> convert it into a unicode string.
Ah, ok. So still a problem of wrong expectations :P
Thanks!

Ben

Re: [flask] Wrong expactation using Markup()?

From:
Armin Ronacher
Date:
2010-08-17 @ 09:08
Hi,

On 8/17/10 10:40 AM, Ben Zimmer wrote:
> Am I doing something wrong, or are just my expactations regarding
> Markup() wrong?
Markup is working fine and so does the usage you pasted above, maybe you 
could paste some more code to reproduce that.  I suppose you are losing 
the markup information somewhere.


Regards,
Armin