在此服务器找不到请求的url,在此服务器上找不到请求的URL。姜

我试着把评论写在页面上,然后改为在页面上重定向我有一个空窗口在浏览器和

[b'

Not Found

The requested URL /post/add_comment/test_single_post/ was not found on this server.

']和{}

在终端日志中。

我不明白为什么在这种情况下找不到页面(404)。在

视图class SinglePost(DetailView):

model = Post

template_name = 'post.html'

def get_context_data(self, **kwargs):

comment_form = CommentForm

context = super(SinglePost, self).get_context_data(**kwargs)

comments = Comments.objects.filter(comment_id=self.object).order_by('-added')

context['comments'] = comments

context['form'] = comment_form

return context

@csrf_protect

def add_comment(request, slug):

"""

Add comment to.

"""

if request.POST:

form = CommentForm(request.POST)

if form.is_valid():

comment = form.save(commit=False)

comment.comment = Post.objects.get(slug=slug)

form.save()

return redirect('/post/{0}/'.format(slug))

网址

^{pr2}$

模板

Comments:

{% for comment in comments %}

{{ comment.added }} | {{ comment.author }}

{{ comment.comment_text }}

{% empty %}

There are no comments here yet. Be first :)

{% endfor %}

{% csrf_token %}

{{ form.non_field_errors }}

{{ form.subject.errors }}

Add your name:

{{ form.author|addclass:"form-control" }}

Add your comment here:

{{ form.comment_text|addclass:'form-control comment-textarea' }}

谁能给我一个如何解决这个问题的答案吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值