46👍
Although it’s quite past when the OP posted the question, but for other people that may need the info, this seems to work well for me:
You can rewrite
{{ game.description|safe|slice:"65" }}
as
{% with description=game.description|safe %}
{{description|slice:"65"}}
{% endwith %}
11👍
Is description an array or a string?
If it is a string, you might want to try truncatewords
(or truncatewords_html
if the description can contain HTML),
{{ game.description|safe|truncatewords:65 }}
Reference: Built-in filter reference, truncatewords.
(I’m new to Django so my apologies if slice works on strings.)
- [Django]-React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)
- [Django]-Django Template Ternary Operator
- [Django]-Generating PDFs from SVG input
3👍
change
{{ game.description|safe|slice:"65" }}
to
{{ game.description|safe|slice:":65" }}
you are missing the colon
- [Django]-Django conditionally filtering objects
- [Django]-Can I use Socket.IO with Django?
- [Django]-Format numbers in django templates
0👍
This may work:
{% filter force_escape|lower %}
This text will be HTML-escaped, and will appear in all lowercase.
{% endfilter %}
Reference: Built-in tag reference, filter.
- [Django]-How do I get the default value for a field in a Django model?
- [Django]-Managing static files for multiple apps in Django
- [Django]-Using django-rest-interface
Source:stackexchange.com