librelist archives

« back to archive

Populating the Textarea in HTML form

Populating the Textarea in HTML form

From:
pronoyc@gmail.com
Date:
2012-12-21 @ 11:41
Hi,

I'd like the ability to edit earlier fed content (in the db) by dumping the
existing data into a Textarea in an HTML Form. Right now, It only dumps it
within HTML tags and doesn't parse them. Jinja's autoescape also doesn't
seem to do the trick.

The thing is, I am dumping data directly from a Mongodb object so I don't
know how I should go about parsing the data in the view and then sending it
into the template. Is it possible? I have seen WTForms has a functionality
to parse the tags but how to do it on native HTML forms.

-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: [flask] Populating the Textarea in HTML form

From:
Anuj Kumar
Date:
2012-12-21 @ 16:33
You can process your data in your view and then pass the processed data to
template. For example, let's assume you want to work on "About Me" section
of user profile. In your view you can use code like this:

# Fetch a single document from "profile" collection according to user_id.
You can use pymongo.

profile = db.profile.find_one({"userid" : user_id })

#You can then process the aboutme data in anyway you want using python. The
data will be available in profile['aboutme']. How you process your data is
only limited to your requirement and capability of python.

# pass the profile dictionary to profile_edit.html template. It will
contain processed aboutme data.
return render_template('profile_edit.html',profile=profile)


In your template you can access the data using : {{ profile['aboutme'] }} .
Just place it in between <textarea></textarea>.


On Fri, Dec 21, 2012 at 5:11 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:

> Hi,
>
> I'd like the ability to edit earlier fed content (in the db) by dumping
> the existing data into a Textarea in an HTML Form. Right now, It only dumps
> it within HTML tags and doesn't parse them. Jinja's autoescape also doesn't
> seem to do the trick.
>
> The thing is, I am dumping data directly from a Mongodb object so I don't
> know how I should go about parsing the data in the view and then sending it
> into the template. Is it possible? I have seen WTForms has a functionality
> to parse the tags but how to do it on native HTML forms.
>
> --
> Regards,
>
> Pronoy Chopra
> http://blog.pronoy.in <http://www.pronoy.in/about>/
> http://www.twitter.com/pronoyc
>



-- 
Regards,
Anuj Kumar

E-mail      : anuj.kk@gmail.com
Website   : http://www.anujkumar.com
<http://blog.anujkumar.com/>
Facebook : http://www.facebook.com/anujkrk
Twitter      : http://twitter.com/#!/anujkkk

Re: [flask] Populating the Textarea in HTML form

From:
Anuj Kumar
Date:
2012-12-21 @ 16:49
If Flask/Jinja is escaping your HTML data submitted through text area i.e.
"<b>hello</b>" becomes "&lt;b&gt;hello&lt;/b&gt;", you can
use "| safe" filter of jinja. Like this :

{{ profile['aboutme'] | safe }}



On Fri, Dec 21, 2012 at 10:03 PM, Anuj Kumar <anuj.kk@gmail.com> wrote:

> You can process your data in your view and then pass the processed data to
> template. For example, let's assume you want to work on "About Me" section
> of user profile. In your view you can use code like this:
>
> # Fetch a single document from "profile" collection according to user_id.
> You can use pymongo.
>
> profile = db.profile.find_one({"userid" : user_id })
>
> #You can then process the aboutme data in anyway you want using python.
> The data will be available in profile['aboutme']. How you process your data
> is only limited to your requirement and capability of python.
>
> # pass the profile dictionary to profile_edit.html template. It will
> contain processed aboutme data.
> return render_template('profile_edit.html',profile=profile)
>
>
> In your template you can access the data using : {{ profile['aboutme'] }}
> . Just place it in between <textarea></textarea>.
>
>
> On Fri, Dec 21, 2012 at 5:11 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:
>
>> Hi,
>>
>> I'd like the ability to edit earlier fed content (in the db) by dumping
>> the existing data into a Textarea in an HTML Form. Right now, It only dumps
>> it within HTML tags and doesn't parse them. Jinja's autoescape also doesn't
>> seem to do the trick.
>>
>> The thing is, I am dumping data directly from a Mongodb object so I don't
>> know how I should go about parsing the data in the view and then sending it
>> into the template. Is it possible? I have seen WTForms has a functionality
>> to parse the tags but how to do it on native HTML forms.
>>
>> --
>> Regards,
>>
>> Pronoy Chopra
>> http://blog.pronoy.in <http://www.pronoy.in/about>/
>> http://www.twitter.com/pronoyc
>>
>
>
>
> --
> Regards,
> Anuj Kumar
>
> E-mail      : anuj.kk@gmail.com
> Website   : http://www.anujkumar.com
> <http://blog.anujkumar.com/>
> Facebook : http://www.facebook.com/anujkrk
> Twitter      : http://twitter.com/#!/anujkkk
>



-- 
Regards,
Anuj Kumar

E-mail      : anuj.kk@gmail.com
Website   : http://www.anujkumar.com
<http://blog.anujkumar.com/>
Facebook : http://www.facebook.com/anujkrk
Twitter      : http://twitter.com/#!/anujkkk

Re: [flask] Populating the Textarea in HTML form

From:
pronoyc@gmail.com
Date:
2012-12-21 @ 18:02
> If Flask/Jinja is escaping your HTML data submitted through text area i.e.
> "<b>hello</b>" becomes "&lt;b&gt;hello&lt;/b&gt;", you can
> use "| safe" filter of jinja. Like this :
>
> {{ profile['aboutme'] | safe }}
>

Turns out it isn't escaping my HTML, but it isn't parsing it either. The
source reflects the tags as consistent HTML and not ascii code. Which means
it needs to be processes before it is passed to the template. I am going to
try that out now.


> You can process your data in your view and then pass the processed data to
>> template. For example, let's assume you want to work on "About Me" section
>> of user profile. In your view you can use code like this:
>>
>> # Fetch a single document from "profile" collection according to user_id.
>> You can use pymongo.
>>
>> profile = db.profile.find_one({"userid" : user_id })
>>
>> #You can then process the aboutme data in anyway you want using python.
>> The data will be available in profile['aboutme']. How you process your data
>> is only limited to your requirement and capability of python.
>>
>> # pass the profile dictionary to profile_edit.html template. It will
>> contain processed aboutme data.
>> return render_template('profile_edit.html',profile=profile)
>>
>>
>> In your template you can access the data using : {{ profile['aboutme'] }}
>> . Just place it in between <textarea></textarea>.
>>
>
Makes sense. Should try this out.

-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: [flask] Populating the Textarea in HTML form

From:
熊军
Date:
2013-01-06 @ 07:51
I am a new man. I can not understand the three difference-blueprint, 
module and template. please help me!

Date: Fri, 21 Dec 2012 23:32:42 +0530
From: pronoyc@gmail.com
Subject: Re: [flask] Populating the Textarea in HTML form
To: flask@librelist.com


If Flask/Jinja is escaping your HTML data submitted through text area i.e.
"<b>hello</b>" becomes "&lt;b&gt;hello&lt;/b&gt;", you can
use "| safe" filter of jinja. Like this :




{{ profile['aboutme'] | safe }}
Turns out it isn't escaping my HTML, but it isn't parsing it either. The 
source reflects the tags as consistent HTML and not ascii code. Which 
means it needs to be processes before it is passed to the template. I am 
going to try that out now.

 
You can process your data in your view and then pass the processed data to
template. For example, let's assume you want to work on "About Me" section
of user profile. In your view you can use code like this:





# Fetch a single document from "profile" collection according to user_id. 
You can use pymongo.

profile = db.profile.find_one({"userid" : user_id }) 

#You can then process the aboutme data in anyway you want using python. 
The data will be available in profile['aboutme']. How you process your 
data is only limited to your requirement and capability of python.




# pass the profile dictionary to profile_edit.html template. It will 
contain processed aboutme data.
return render_template('profile_edit.html',profile=profile)


In your template you can access the data using : {{ profile['aboutme'] }} 
. Just place it in between <textarea></textarea>.


Makes sense. Should try this out. -- 
Regards,
Pronoy Choprahttp://blog.pronoy.in/

http://www.twitter.com/pronoyc