有人能看到我在做错了什么吗?我错过了什么?
# 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})
答案 0 :(得分: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')})