P
P
Pennyw1se2018-02-01 19:10:27
Django
Pennyw1se, 2018-02-01 19:10:27

How to cut text from the database in a template?

How to trim up to 50 characters data from the {{ post.text }} field in models.py on index.html?

<div class="section">
        <div class="container">
            <div class="row">


                {% for post in latest_post_list %}
                    <div class="col-lg-3">
                        <div class="card" style="width: 18rem;">
                            <img class="card-img-top" src="{{ post.image.url }}" alt="Card image cap" width="268" height="180">
                                <div class="card-body">
                                    <h5 class="card-title">{{ post.title }}</h5>
                                    <p class="card-text">{{ post.text }}</p>
                                    <a href="#" class="btn btn-primary">Читать</a>
                                </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question