让这些模型:
class Category(models.Model):
name = models.CharField(max_length=20)
class Word(models.Model):
name = models.CharField(max_length=200)
categories = models.ManyToManyField(Category, null=True, blank=True)
而这个观点:
def main_page(request):
words = Word.objects.all()
return render(request, "main_page.html", {'words': words})
如何按类别过滤单词,将类别作为模板中的参数传递?