librelist archives

« back to archive

render_to_template

render_to_template

From:
Filipe Cifali
Date:
2012-07-27 @ 20:29
Hello, I'm new here and I would like to ask, if I can, a little help.

Right now I'm working in a mini-site that do some network featuries and I
already accomplished "a little" that it needs to be:

<goog_711113060>
https://github.com/filipecifali/Flask-Ping-Site

So, what I need to know, how can I format return_data so I can read its
lines with a <br> in it(for usage on template/base.hml

Should I loop inside the template? How could that be done?

<goog_711113063>
https://github.com/filipecifali/Flask-Ping-Site/blob/master/templates/center.html

Thank you in advance!

-- 
[]'s

Filipe Cifali Stangler

Re: [flask] render_to_template

From:
Simon Sapin
Date:
2012-07-28 @ 06:19
Le 27/07/2012 22:29, Filipe Cifali a écrit :
> So, what I need to know, how can I format return_data so I can read its
> lines with a <br> in it(for usage on template/base.hml
>
> Should I loop inside the template? How could that be done?

You could split on newlines and insert <br> element, but there is an 
easier way. If you only want to preserve all whitespace formatting, use 
<pre>:

{% if return_data %}
     <pre>{{ return_data }}</pre>
     ...

You can control the white-space processing in CSS with the property 
named … white-space.
https://developer.mozilla.org/En/CSS/white-space

    <pre style="white-space: nowrap">{{ return_data }}</pre>

Regards,
-- 
Simon Sapin

Re: [flask] render_to_template

From:
Filipe Cifali
Date:
2012-07-28 @ 13:07
Thank you both, I really need to learn a lot to find these easy ways faster
instead of asking. ("-_-)

Just learned 2 different ways now!

Since docs does not have any example for context_processor()

I "cheated" and the <pre> did the work as I wanted to be :)

@Anderson,

yeap, but I'm just a sysadmin trying to learn something new and exciting as
further more I learn about python.


2012/7/28 Simon Sapin <simon.sapin@exyr.org>

> Le 27/07/2012 22:29, Filipe Cifali a écrit :
> > So, what I need to know, how can I format return_data so I can read its
> > lines with a <br> in it(for usage on template/base.hml
> >
> > Should I loop inside the template? How could that be done?
>
> You could split on newlines and insert <br> element, but there is an
> easier way. If you only want to preserve all whitespace formatting, use
> <pre>:
>
> {% if return_data %}
>      <pre>{{ return_data }}</pre>
>      ...
>
> You can control the white-space processing in CSS with the property
> named … white-space.
> https://developer.mozilla.org/En/CSS/white-space
>
>     <pre style="white-space: nowrap">{{ return_data }}</pre>
>
> Regards,
> --
> Simon Sapin
>



-- 
[]'s

Filipe Cifali Stangler

Re: [flask] render_to_template

From:
Anderson Cardoso
Date:
2012-07-27 @ 21:04
Hi filipe,
If I understood your question, you want to format you output with html,
right?
you can create a context_processor (expose a function in your template),
and return a Markup object:

@app.context_processor
def format_data():
    def _format_data(text):
        # do some formating in text
        return Markup(text)
    return dict(format_data=_format_data)

Now, in any template:
 {{ format_data(return_data) }}

This is one way, there are several others. You can create a jinja filter,
or return your return_data already marked (use the Markup object for this,
or the  'safe'  filter), etc

I hope this helps. If is not what you meant, let us know.
att

Anderson

PS: you are from the python-br community, aren't you? I remember seeing
your name there. Nice to see more brazilians here =]

2012/7/27 Filipe Cifali <cifali.filipe@gmail.com>

> Hello, I'm new here and I would like to ask, if I can, a little help.
>
> Right now I'm working in a mini-site that do some network featuries and I
> already accomplished "a little" that it needs to be:
>
> <http://goog_711113060>
> https://github.com/filipecifali/Flask-Ping-Site
>
> So, what I need to know, how can I format return_data so I can read its
> lines with a <br> in it(for usage on template/base.hml
>
> Should I loop inside the template? How could that be done?
>
> <http://goog_711113063>
>
> 
https://github.com/filipecifali/Flask-Ping-Site/blob/master/templates/center.html
>
> Thank you in advance!
>
> --
> []'s
>
> Filipe Cifali Stangler
>
>


-- 
Anderson Pierre Cardoso
Computer Engineer - University of São Paulo
*
http://www.apierrecardoso.com*
twitter: *@apierre_cardoso* <https://twitter.com/#%21/apierre_cardoso>