Redirect after comment submission in Django not working with django.contrib.comments.moderation?

StackOverflow https://stackoverflow.com/questions/4125243

  •  29-09-2019
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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'])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top