在 Django 中提交评论后重定向无法与 django.contrib.comments.moderation 一起使用?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在单独的视图中进行重定向解决了我的问题:
urls.py
views.py
Doing a redirect in a separate view solved my issue:
urls.py
views.py