6

How can i pass QuerySet object in to template. And then Iterate through it in tempalte. If ican do it....?

Example

queryset =MyModel.objects.all()

return render_to_response('template.html',{'queryset':queryset})

How it'll looks in template?

Can I show field of foreigne key object in this template?

1 Answer 1

7
{% for each_model in model %}
    #Do Something with model
    {{each_model.name}}
{% endfor %}
Sign up to request clarification or add additional context in comments.

2 Comments

@Pol - Sure. {{ each_model.someForeignKey.someField }}
How would I pass each_model to another template that has been included? Something like {% for each_model in model %} {{render each_model as "model_card.html"}} {% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.