1👍
✅
In Django’s views you usually pass such values as context
.
function based view:
def a_view(request):
context = {
'some_things': Thing.objects.all()
}
return render(request, 'your_template.html', context)
class based view:
class TheView(View):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['some_things'] = Thing.objects.all()
return context
With any of given approaches in template it will work like this:
{% for thing in some_things %}
{{ thing }}, {{ thing.id }}, {{ thing.get_related_things }}
{% endfor %}
Source:stackexchange.com