How can I use a variable as index in django template?
Right now I get this error:
Exception Type:
TemplateSyntaxError
Exception Value:
Could not
I don't think this is directly possible (edit: you can manually implement it with filters, as shown in goliney's answer). The documentation says:
Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display.
If your case is not more complicated than what you're showing, the best solution in my opinion would be to loop over bikeProfit
instead.
{% for year, profit in bikeProfit.items %}
...
Total profit {{ year }}:
...
{{ profit }}
...