How to replace space into &nbsp in Django template?

For replacing a space with &nbsp , you may use one of following Template Tags based solution:

1) nbsp filter Replaces usual spaces in string by non breaking spaces

2) Regular Expression Replace Template Filter This will perform a regular expression search/replace on a string in your template.

3) Stackoverflow post, @Paolo Bergantino's answer Suggests to make a custom template tag


CSS

.nbsp {
    white-space: nowrap;
}

Template

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

This should also help without processing text on server side.