[PYTHON] Django Template Tips

Access object by array number

template.html


{{ objects.0.name }}

Add line numbers to the table

template.html


            <table class="table table-striped">
                <thead class="thead-dark">
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">Name</th>
                </tr>
                </thead>
                <tbody>
                    {% for object in object_list %}
                        <tr>
                            <th scope="row">{{ forloop.counter }}</th>
                            <td>{{ object.name }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>

Update whenever you come up with

Recommended Posts

Django Template Tips
Django # 2 (template)
Django Template notes
Django HTML template
Django template file organization
Django Rest Framework Tips
Django
Template registration from Django Bootstrap
Show Django ManyToManyField in Template
template
Make a filter with a django template
[Tips] How to do template extends when creating HTML with django
How to do arithmetic with Django template
django update
Django memorandum
python tips
django search
Django installation
Jupyter Tips 4
Django Summary
Django test
numpy tips
Jupyter Tips 5
Scapy Tips
Jupyter Tips 3
(Note) Template file search order in Django
Django Note 5
Jupyter Tips 2
Django hands-on
Touch django
django notes
Django Summary
Django basics
Django Shoho
WEB application development using Django [Template addition]
Django defaults
Django + Docker
Django Glossary
Django search
(For myself) Django_1 (Basic / Hello World / Template)
Install Django
Django: References
Django Note 1
Django note 3
Django note 2
Resolve Angural JS and Django template conflicts
Django startup
Python Tips
Write a short if-else for Django Template
Python tips
Django notes
Django NullCharField
Specify the view URL in your Django template