I am using the following code to dynamically generate the content of my HTML table using Web2Py helpers:
response_results = []
for row in db(db.table.column_name == selected_column_val).select(db.table.ALL):
body_col = row.body_col
row_data = ['Col 1', row.col2, body_col.replace(".", ".<br/><br/>"), row.col4]
response_results.append(row_data)
html = DIV(TABLE(THEAD(TR(TH('Row #'), TH('Col 1'), TH('Col 2'), TH('Col 3'), TH('Col 4')), _id=0),
*[TR(response) for response in response_results],
_id='records_table', _class='table table-bordered'),
_class='table-responsive')
Basically, in here I need to render the content of the body_col in such a way that it's more readable so I am trying to add some newlines after each period '.'. I have tried using these two but none of them make any difference: body_col.replace(".", ".<br/><br/>")
and body_col.replace(".", ".\n\n")
.
Regarding the output displayed:
- When I directly add the output with the
<br/>
tags in HTML it looks fine.
Input:
This is line one.
This is line two.
This is line three.
This is line four.
This is line five.
Output:
This is line one.
This is line two.
This is line three.
This is line four.
This is line five.
- When I render the output HTML dynamically using
body_col.replace(".", ".\n\n")
, it all comes as a single line without any line breaks.
Input:
This is line one.
This is line two.
This is line three.
This is line four.
This is line five.
Output:
This is line one. This is line two. This is line three. This is line four. This is line five.
- When I render the output HTML dynamically using
body_col.replace(".", ".<br/><br/>")
, it all comes as a single line without any line breaks but with literal<br/>
tags displayed.
Input:
This is line one.
This is line two.
This is line three.
This is line four.
This is line five.
Output:
This is line one.<br/><br/>
This is line two.<br/><br/>
This is line three.<br/><br/>
This is line four.<br/><br/>
This is line five.
Even when I analyze the input/output text in Notepad++ to check the presence of CR LF characters. I notice that the CR LF are always present except only when being generated dynamically. In that case there are no CR LF characters present, even though they were there in the input data of body_col
. Somehow, they all are getting stripped out while Web2Py HTML helpers generate the output table.
I referred to this link as well but couldn't quite get it to apply for my specific need.
Can somebody guide me how can I accomplish this task?
All your help would be greatly appreciated.
" version? – Anthony Aug 12 '15 at 00:34
" version were actually resulting in any replacements, then you would see literal "
" strings in the visible output (because you haven't wrapped the HTML in an XML() helper). Also, web2py does not remove line feeds (though line feeds in the text would not result in actual line breaks in the rendered HTML). Something is missing from your above code or sample data. I suggested creating a minimal app that reproduces the problem and posting it to the Google Group. – Anthony Aug 12 '15 at 20:51
" strings in the rendered output, as would be expected based on your code). – Anthony Aug 12 '15 at 21:02