How to replace space with & nbsp in a Django template?

I have a model with multi-line text fields that was introduced from textarea.

Now I want to display this field, but I do not want to use the tag <pre>.

I just want to replace the new line with <br/>, and I found a filter linebreakbr.

But I also want to replace the space &nbsp;. Not indicated in the documentation.

Can anyone help?

+5
source share
2 answers

To replace the space with & nbsp, you can use one of the following template-based solutions:

1) nbsp filter

2) / .

3) fooobar.com/questions/388865/...

+9

CSS

.nbsp {
    white-space: nowrap;
}

<div class="nbsp">Any text you want</div>

.

0

All Articles