Connecting Tech Pros Worldwide Forums | Help | Site Map

Formatting data to output in web browser from web form

Harlin Seritt
Guest
 
Posts: n/a
#1: Jul 21 '05
Hi,

I am using CherryPy to make a very small Blog web app.

Of course I use a textarea input on a page to get some information.
Most of the time when text is entered into it, there will be carriage
returns.

When I take the text and then try to re-write it out to output (in html
on a web page), I notice the Python strings don't translate these
special characters (carriage returns) to a "<p>" so that these
paragraphs show up properly in html for output. I tried doing something
like StringData.replace('\n', '<p>'). Of course this doesnt work
because it appears that '\n' is not being used.

Is there anything I can do to make sure paragraphs show up properly?

Thanks,

Harlin Seritt


John Machin
Guest
 
Posts: n/a
#2: Jul 21 '05

re: Formatting data to output in web browser from web form


Harlin Seritt wrote:[color=blue]
> Hi,
>
> I am using CherryPy to make a very small Blog web app.
>
> Of course I use a textarea input on a page to get some information.
> Most of the time when text is entered into it, there will be carriage
> returns.
>
> When I take the text and then try to re-write it out to output (in html
> on a web page), I notice the Python strings don't translate these
> special characters (carriage returns) to a "<p>" so that these
> paragraphs show up properly in html for output. I tried doing something
> like StringData.replace('\n', '<p>'). Of course this doesnt work
> because it appears that '\n' is not being used.
>
> Is there anything I can do to make sure paragraphs show up properly?
>[/color]

The ASCII carriage return (CR) is represented in Python as "\x0d" or
"\r". The line feed (LF) is "\x0a" or "\n". Does this info help you with
your problem? If, not perhaps you might like to

print repr(StringData)

so that we can see what you are calling "carriage returns".

HTH,
John
Harlin Seritt
Guest
 
Posts: n/a
#3: Jul 21 '05

re: Formatting data to output in web browser from web form


This is perfect. Thanks!

Closed Thread