1

有人能看到我在这里做错了吗?我错过了什么?

# works
{% get_comment_count for app.somemodel object_pk as comment_count %}
{% get_comment_count for model as comment_count %}

# Throws error: "Caught AttributeError while rendering: 'str' object has no attribute '_meta'"
{% render_comment_list for app.somemodel %}
{% render_comment_form for app.somemodel %}

# Gives an empty form and empty list
{% render_comment_list for model %}
{% render_comment_form for model %}

风景:

# view.py
from app.models import SomeModel

def some_view(request):

    return render_to_response("app/some_template.html", {'model': SomeModel})
4

1 回答 1

1

我从未使用过评论框架,但我会继续建议传入一个模型实例——如何为模型类呈现评论表单或列表?

注释与模型及其 ID 具有通用关系。您不能对模型类发表评论。

http://docs.djangoproject.com/en/dev/ref/contrib/comments/#displaying-the-comment-post-form

def some_view(request):
    # pass in an instance, not a class, if you want to render a comment form
    return render_to_response("app/some_template.html", {'model': SomeModel.objects.latest('id')})
于 2011-03-04T15:00:47.340 回答