Using django_comments but getting 'QuerySet

2019-09-08 15:19发布

问题:

My django project named comments is here. It has an app comms which is there to display comments using django_comments.

I have

  1. installed django_comments
  2. put it in INSTALLED_APPS field in settings.py
  3. have defined SITE_ID = 1
  4. enabled the sites framework
  5. put url(r'^comments/', include('django_comments.urls')) in urls.py

But this template file is giving me this error:

AttributeError at /

'QuerySet' object has no attribute '_meta'

What am I missing?

回答1:

Change your home.html to something like:

{% load comments %}
<html>
    {% for entry in categ %}
        {% get_comment_count for entry as comment_count %}
        {% render_comment_list for entry %}
    {% empty %}
        <p> categ not present </p>
    {% endfor %}
</html>

As I understand the template tags take an object as parameter, but you have provided the Queryset(Category.objects.all()).

Not tested the code, but something similar should work.