This is my code in templates:
{% for wine_con in data.winry_consult %}
<li><a href="/article_list_content-{{win_con.id}}/"><p>{{ win_con.content }}</p><i class="font"></i></a></li>
{% endfor %}
I found the win_con.content
is too long for my website, I only want 5 count characters, how can I cut out the win_con.content
in template?
Django-Truncate is a simple library that will add the ability to empty any given model in any app within your django project, in a more SQL related words it will TRUNCATE the TABLE with a simple command: python manage.py truncate --apps myapp --models model1 model2.
To override these templates, you will need to have an admin folder in your templates folder. If you do not have a templates folder, you can create it in the main project folder. To do so, you will have to change the project's settings.py . Find the TEMPLATES section and modify accordingly.
Being a web framework, Django needs a convenient way to generate HTML dynamically. The most common approach relies on templates. A template contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
you may use built-in filter truncatechars
{{ win_con.content|truncatechars:5 }}
https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#truncatechars should help
{{ value|truncatechars:9 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With