Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a line break in Django template

I want to give default value to a textarea. The code is something like this:

<textarea>{{userSetting.list | join:"NEWLINE"}}</textarea>

where userSetting.list is a string list, each item of whom is expected to show in one line.

textarea takes the content between the tags as the default value, preserving its line breaks and not interpreting any HTML tags (which means <br>,\n won't work).

I have found a solution: {{userSetting.list | join:" " | wordwrap:0}} (there is no whitespace in the list). But obviously it is NOT a good one. Any help would be appreciated.

like image 682
iamamac Avatar asked Apr 12 '10 12:04

iamamac


1 Answers

Since Chris didn't come and collect the credit, I have to answer my question myself. (But still thanks him for pointing to the right direction)

The HTML entity &#10; stands for a NEWLINE character, and won't be interpreted in Django template. So this will work:

<textarea>{{userSetting.list | join:"&#10;"}}</textarea>
like image 51
iamamac Avatar answered Sep 23 '22 18:09

iamamac