1
Django 1.10
, docs here,
Use truncatechars
, rjust
together.
index.html
<p>Non formated string</p>
<p>{{ "Truncatechars (include ... length)"|truncatechars:10}}</p>
<p>{{ "Truncatechars with rjust"|truncatechars:10|rjust:"30" }}</p>
<p>{{ "Only rjust"|rjust:"30" }}</p>
Output
Template renders correct HTML as below.
Please note white-space: pre;
css property to represent white-space.
p {
white-space: pre;
}
<p>Non formated string</p>
<p>Truncat...</p>
<p> Truncat...</p>
<p> Only rjust</p>
About white-space, see here
0
Use in-bulit truncatechars
template tag
{{ "my too long or too short string"|truncatechars:10 }}
- Nginx reverse proxy for nginx+gunicorn+django server
- Forbidden (403) CSRF verification failed. Request aborted. Django
- User selects language on login page using form django
- Why uses South to do migration in Django?
Source:stackexchange.com