I would like to display something like this in my template:
Name: John
Age: 18
City: New York
Using, for example, this code:
views.py
def person_details(request,pk):
person = get_object_or_404(Person, id=pk)
return render(request, 'template.html', {'person': person, 'person_fields': person._meta.get_fields()})
template.html
{% for field in person_fields %}
<div class="col-4 form-group">
<p><strong>{{ field.verbose_name }}:</strong> {{ person[ field.name ] }}</p>
</div>
{% endfor %}
Is this possible in python? I ask because I have a model that have about 20 fields and hard coding the fields in template would be a little hard.