How do I display all the elements in a list with a line break in a Django template?
For example, with a list
ls = ['bin', 'boot', 'data', 'data2'] I would like to display the elements in the format
bin
boot
data
data2
I have tried:
'\n'.join(ls)
This returns each word with spaces:
b i n b o o t d a t a d a t a 2
The relevant code from my views.py:
result1 = subprocess.Popen(['ls', '/home/zurelsoft/R'], stdout=subprocess.PIPE).communicate()[0]
result = ''.join(result1)
return render_to_response('thanks.html', {'res':result, 'res1':command}, context_instance=RequestContext(request))
The corresponding section of the template:
<td>{{ res }} </td>
Modify your view to use the
splitlines()function to split the output into a list of lines:And then use the join filter in your template to separate each element in the list with the HTML line-break tag
<br />: