Traversing foreign key related tables in django templates

后端 未结 1 1455
小蘑菇
小蘑菇 2020-12-30 20:24

View

categories = Category.objects.all()
t = loader.get_template(\'index.html\')
v = Context({
    \'categories\': categories
})
return HttpResponse(t.rend         


        
相关标签:
1条回答
  • 2020-12-30 21:06

    Just get rid of the parentheses:

    {% for company in category.company_set.all %}
    

    Here's the appropriate documentation. You can call methods that take 0 parameters this way.

    0 讨论(0)
提交回复
热议问题