在 Django 中提交评论后重定向无法与 django.contrib.comments.moderation 一起使用?

发布于 2024-10-01 12:45:24 字数 913 浏览 2 评论 0原文

我正在使用 django.contrib.comments 来启用博客评论。

我在评论表单中添加了一个隐藏的“下一个”字段,其中包含我希望用户在提交评论后返回的 url,以便绕过 posts.html 模板,该模板工作正常:

<input name="next" type="hidden" value="{% url single_post slug=post.slug %}" />

但是,在实施之后评论主持人如下:

from django.contrib.comments.moderation import CommentModerator, moderator
class PostModerator(CommentModerator):
    email_notification = True

moderator.register(Post, PostModerator)

,有一个错误抱怨文件 comments/comment_notification_email.txt 丢失,所以我创建了如下文件:

Comment: http://127.0.0.1{{ comment.get_absolute_url }}
From: {{ comment.person_name }}

-----
{{ comment.comment }}
-----

Admin: http://127.0.0.1/admin/comments/comment/{{comment.id}}/

但现在,Django 抱怨请求 URL http://127.0.0.1:8000/comments/post/ 不存在?如何最好地解决这个问题?

I'm using django.contrib.comments for enabling comments on a blog.

I was adding a hidden 'next' field to the comment form with the url to which I'd like the user to return after they submit their comment in order to bypass the posted.html template, which was working properly:

<input name="next" type="hidden" value="{% url single_post slug=post.slug %}" />

However, after implementing the comment moderatar as follows:

from django.contrib.comments.moderation import CommentModerator, moderator
class PostModerator(CommentModerator):
    email_notification = True

moderator.register(Post, PostModerator)

, there was an error complaining that the file comments/comment_notification_email.txt was missing, so I created the file as follows:

Comment: http://127.0.0.1{{ comment.get_absolute_url }}
From: {{ comment.person_name }}

-----
{{ comment.comment }}
-----

Admin: http://127.0.0.1/admin/comments/comment/{{comment.id}}/

But now, Django complains that the request URL http://127.0.0.1:8000/comments/post/ does not exist? How can this issue be best solved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2024-10-08 12:45:24

在单独的视图中进行重定向解决了我的问题:

urls.py

(r'^comments/post/', 'app.views.comment'),

views.py

def comment(request):
    # Redirecting after comment submission
    return HttpResponseRedirect(request.POST['next'])

Doing a redirect in a separate view solved my issue:

urls.py

(r'^comments/post/', 'app.views.comment'),

views.py

def comment(request):
    # Redirecting after comment submission
    return HttpResponseRedirect(request.POST['next'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文