[Answered ]-Concatenate lines of form input into a single line

1👍

newstring = input.replace('\n', '') should work

1👍

Use

" ".join(input.split("\n"))

0👍

Thank you Harrison and Cychih for your answer, I tried however, they don’t work. The solution I found is this :

newstring = input1.replace('\r\n', ' ')

It’s

'\r\n'

not

'\n'

When I put in the form 3 lines like this ;

Line 1
Line 2
Line 3

Here is the output of the request.POST

<QueryDict: {'input1': ['Line 1 \r\nLine 2\r\nLine 3\r\n'], 'csrfmiddlewaretoken': ['tvC0ISHPNEkdQzocuVRnhJCp5yadDkgC5wf832blrpYPP0MZVV1iNY5bI2cYXsA4'], 'output1': [' ']}>

I don’t know why new line is set as \r\n but it’s the way it is .

Thank you again for your help!

Leave a comment