Formatting data to output in web browser from web form

H

Harlin Seritt

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
 
J

John Machin

Harlin said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top