I have a field like this in my Django template:
<p>{{news.description}}<p>
I wanna show the first 50 words of this field. How can I do it?
Use {{ obj | capfirst }} to make uppercase the first character only. Using {{ obj | title }} makes it Camel Case.
For example, adding an argument null = True to TextField will enable it to store empty values for that table in relational database. Here are the field options and attributes that an TextField can use. If True, Django will store empty values as NULL in the database. Default is False.
{% include %}: this will insert a template within the current one. Be aware that the included template will receive the request's context, and you can give it custom variables too.
lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates.
From the documentation:
{{ news.description|truncatewords:50 }}
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