I have a problem with getting a data in template. I am writing code in python file its working.
students = Student.objects.all()
for x in students:
print(x.parent.get(gender='M').fullname)
It gets me Parent Fullname
, but when i write it in template like:
{% for x in students %}
<td class="small d-none d-xl-table-cell text-center">{{ x.parent.{%get(gender='F')%}.fullname }}</td>
{% endfor %}
it gets me Could not parse the remainder: '{%get(gender='F')%}.fullname' from 'x.parent.{%get(gender='F')%}.fullname'
error. I tried write it like {{ x.parent.get(gender='F').fullname }}
but i get same error
Same code working in python file but not working in template.
You can't do that: Django's template language is deliberately limited to prevent people from writing business logic in the template.
You can define this in the
Student
model:Then you use:
in the template.