[Fixed]-Querying ManyToMany fields in Django

1👍

✅

You have misspelled occupation in your template.

{% for skill in ocuppation.skills.all %}

It should be

{% for skill in occupation.skills.all %}

Here’s a tip for debugging next time. When the for loop didn’t print anything, I would try to include the queryset I was looping over.

{{ ocuppation.skills.all }}

and if that didn’t work, try the instance itself

{{ ocuppation }}

Then I would know that the problem is with the variable ocuppation, not the many to many field. Hopefully I would then spot the misspelling.

Leave a comment