我想用Ajax创建一个评论系统。我的主要目的是在不刷新页面的情况下获得新的评论。我在我的HTML文件中添加了一些js代码,但是没有用。我的错误在哪里?我该怎么做?在
视图.py...
def post_detail(request, pk, ):
post = get_object_or_404(Post, pk=pk)
form = CommentForm(request.POST or None)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('post_detail', pk=post.pk)
context = {
'post': post,
'form': form,
}
return render(request, 'blog/post_detail.html', context)
评论.html
^{pr2}$
发布_详细信息.html...
{% include 'blog/comment.html' %}
{% for comment in post.comments.all %}
{{ comment.name }} | {{ comment.created_date|timesince }} önce
{{ comment.content|linebreaks }}
{% endfor %}
网址.py...
url(r'^post/(?P\d+)/$', views.post_detail, name='post_detail'),
当我点击评论按钮没有任何动作。但当我查看检查元素时,当我点击按钮时,它会显示状态代码:403
注意:我得到“耶!它起作用了!”警惕