使用内置注释框架时出错
|
我正在尝试使用内置的注释框架,但无法使其正常工作。这是代码:
#view.py
from django.contrib.comments.forms import *
from forms import *
from models import *
def view_item_detail(request, item_id):
item = Item.manager.get(item_id)
form = CommentForm(item)
if request.POST:
form = CommentForm(request.POST)
if form.is_valid():
new_comment = form.save(commit=False)
# do stuff here
new_comment.save()
messages.success(request, \"Your comment was successfully posted!\")
return HttpResponseRedirect(\"\")
return render_to_response(\'item_detail.html\',
RequestContext(request, {\'item\': item,
\'authentication\': request.user.is_authenticated(),
\'user\': request.user, \'form\': form}))
和
#item_detail.html
{% if authentication %}
{% if form %}
<form action=\"\" method=\"post\">{% csrf_token %}
{{ form }}
<p><input type=\"submit\" name=\"submit\" value=\"Submit comment\" /></p>
</form>
{% endif %}
{% else %}
<p>You must be logged-in to post a comment</p>
{% endif %}
我收到的错误是\“ \'QueryDict \'对象没有属性''_meta \'\',该属性来自行
form = CommentForm(request.POST)
任何帮助将不胜感激,欢呼。
没有找到相关结果
已邀请:
1 个回复
锑寝粒
现在确保您的urls.py中包含以下内容:
和
已添加到您的INSTALLED_APPS中,并且已同步 现在,在您的
文件中,您应该添加:
您要在其中显示评论的位置:
您要在其中显示添加评论表单的位置:
请阅读文档
,要进行自定义,请阅读
页。 作为文档的一部分: 指定您想要的URL 重定向到评论后 发布,您可以包含一个隐藏的表单 您评论中的下一个输入 形成。例如:
(为您的示例编辑):