python – Concatenate variables in Django template


Hey guys, good morning, I have a problem. I'm scrolling through a lista but I want to concatenar my list that I'm calling in the template as {{ list }} and {{ forloop.counter0 }} so that my for only displays 1 list item at a time and not all of it

def user_donations(request):
    donations = Donation.objects.all().filter(

    donationItem = DonationItem.objects.all().filter(
    list = []

    for item in donationItem:

    content = {'donations':donations, 'list': list}
    return render(request, 'user-donations.html', content)

{% extends 'base.html' %}
{% load static %}

{% block content%}
<section class="user-donations">
    <div class="register-header-desktop">
        <h2>Minhas doações</h2>
    <div class="container register">
        <div class="donations-list">
            {% for donation in donations %}
            <div class="modal">
                <div class="confirm-school-name">
                    <span>{{ donation.created_at }}</span>
                    <span>De: {{ donation.donor }}</span>
                    <span>Para: {{ }}</span>
                <div class="list-itens">
                    <span>{{ list.forloop.counter0 }}</span>
                <div class="confirm-delivery">
                <div class="arrow">
                    <img src="{% static 'images/arrow-down-icon.png' %}" alt="">
            {% endfor %}
{% endblock %}

But the way I'm trying is not working, can anyone help me?


You just iterate the items on the list using a for it will bring one item per iteration without needing a variable for indexing.

For example to create a list in the Django template we can do this:

<div class="list-itens">
        {% for item in list %}
            <li class="item">{{ item }}</li>
        {% endfor %}
Scroll to Top