[PYTHON] In Django, how to abbreviate the long displayed string as ....

I'm making a blog with Django and it's hard to see even if there is a long sentence on the home, so I was looking for a way to abbreviate it, and I found something like this, so I will share it.

Django version = 2.2.4 Python version = 3.8.2

home_list.html


<p>{{ post.text|linebreaksbr|truncatechars:250 }}</p>

It may be a little confusing, but only the last "truncatechars" is specifically relevant to this article.

By changing the number there to your liking, it will be abbreviated as ... from the next character.

Recommended Posts

In Django, how to abbreviate the long displayed string as ....
How to write custom validations in the Django REST Framework
How to generate a query using the IN operator in Django
How to reflect CSS in Django
Switch the language displayed in Django 1.9
Get the query string (query string) in Django
How to check the version of Django
How to delete expired sessions in Django
How to do Server-Sent Events in Django
How to convert DateTimeField format in Django
How to use the C library in Python
How to implement Rails helper-like functionality in Django
How to embed a variable in a python string
How to reflect ImageField in Django + Docker (pillow)
How to run some script regularly in Django
How to print debug messages to the Django console
How to get the files in the [Python] folder
How to output "Ketsumaimo" as standard output in Python
How to input a character string in Python and output it as it is or in the opposite direction.
How to uniquely identify the source of access in the Django Generic Class View
How to count the number of elements in Django and output to a template
I'm addicted to the difference in how Flask and Django receive JSON data
How to check the version of Django
The easiest way to get started with Django
The easiest way to set up Last-Modified in Flask
update django version 1.11.1 to 2.2
What I did to speed up the string search task
In Django, how to abbreviate the long displayed string as ....
How to retrieve the nth largest value in Python
How to convert / restore a string with [] in python
How to get the variable name itself in python
How to run the Ansible module added in Ansible Tower
How to delete the specified string with the sed command! !! !!
How to get multiple model objects randomly in Django
[Python] How to expand variables in a character string
Set the form DateField to type = date in Django
How to use bootstrap in Django generic class view
How to use the exists clause in Django's queryset
How to use the model learned in Lobe in Python
How to use Decorator in Django and how to make it
How to reference static files in a Django project
[Python] How to output the list values in order
[Django] How to redirect unlogged-in users to the login page
How to find the optimal number of clusters in k-means
How to debug the Python standard library in Visual Studio
How to use Laravel-like ORM / query builder Orator in Django
How to use the generator
How to import NoteBook as a module in Jupyter (IPython)
How to use the __call__ method in a Python class
How to check ORM behavior in one file with django
How to update user information when logging in to Django RemoteUserMiddleware
[Django] How to give input values in advance with ModelForm
How to set the html class attribute in Django's forms.py
How to manipulate the DOM in an iframe with Selenium
How to log in automatically like 1Password from the CLI
How to quickly count the frequency of appearance of characters from a character string in Python?
How to do the initial setup from Django project creation
Display the time in Django according to the user's region (UTC)
I can't log in to the admin page with Django3
Find out how many each character is in the string.
How to develop in Python
Notes on how to use marshmallow in the schema library
Change the message displayed when logging in to Raspberry Pi
How to import NoteBook as a module in Jupyter (IPython)
How to use discrete values as variables in Scipy optimize
[Shell] How to get the remote default branch in Git