Stack Exchange
Could not parse the remainder: '[plant__id]' from 'total_ecof[plant__id]'
My views.py:
def home(request):
    if not request.user.is_authenticated():
        template = 'data/login.html'
        return render(request, template)
    else:
            plants = Plant.objects.filter(user=request.user)
            total_ecof = []
            total_ectr = []
            for plant in plants:
                x = 0
                y = 0
                for recording in Recording.objects.filter(plant__id=plant.id):
                    x += (recording.time_to_detect * recording.performance_loss) / (
                    plant.nominal_power * recording.years_of_operation)
                    y += ((10 + 15 + 200 + 50) * plant.no_modules + 240 * 50 * recording.occurrence * plant.no_modules) / (
                         plant.nominal_power * 3)
                total_ecof.append(x)
                total_ectr.append(y)
        template = 'data/home.html'
        context = {
                    'plants':plants,
                    'total_ecof':total_ecof,
                    'total_ectr':total_ectr,
                    }
        return render(request, template, context)

my html template
{% for plant in plants %}
    <tr>
       <td>{{ plant.management_company }}</td>
       <td>{{ plant.plant_name }}</td>
       <td>{{total_ecof[plnat.id]}}</td>
    </tr>
{% endfor %}

But I get the error: 
Exception Type: TemplateSyntaxError
Exception Value: Could not parse the remainder: '[plant.id]' from 'total_ecof[plant.id]'

and I do not understand why. What am I doing wrong?  
Furthermore, could you please help me to create a bar chart where x axis would be the plants and y axis the corresponding total_ecof. 

In the template, you reference total_ecof[plnat.id].

yes but how can I solve this? I need for example is plant.id =3 then total_ecof[3]

Don't create a separate list for the totals. Either create a single list consisting of (record, total) pairs, or set the total directly on the Recording instances.

As explained in all the other answers and comments - as well as clearly stated in the documentation - you cannot do things like this in the template.

@Exprator and @Daniel thank you for your comments. I found the solution:
First of all in my models.py I added in my class Plant the following:
def total_ecof(self):
    return self

then I changed my views.py:
def home(request):
    if not request.user.is_authenticated():
        template = 'data/login.html'
        return render(request, template)
    else:
            plants = Plant.objects.filter(user=request.user)
            for plant in plants:
                plant.total_ecof = 0
                for recording in Recording.objects.filter(plant__id=plant.id):
                    plant.total_ecof += (recording.time_to_detect * recording.performance_loss) / (plant.nominal_power * recording.years_of_operation)
        template = 'data/home.html'
        context = {
                    'plants':plants
                    }
        return render(request, template, context)

and my html:
{% for plant in plants %}
    <tr>
       <td>{{ plant.management_company }}</td>
       <td>{{ plant.plant_name }}</td>
       <td>{{ plant.total_ecof }}</td>
    </tr>
{% endfor %}

I do not know if it is the best solution but it is working :) thank you guys!!!!!
