Search code examples
pythondjangodjango-comments

Django comments change success url


I would like to change the URL you are redirected to when django posts a comment successfully - I'd much rather be taken to the page where the comment has been posted to, rather than the current redirect to a 'thanks for your comment' URL. Is there a place I can override this in django? Thanks


Solution

  • Just add a hidden field called next to your comment form with the value of the url you'd like to re-direct to after the form has been posted.

    Example from the docs:

    <input type="hidden" name="next" value="{% url my_comment_was_posted %}" />
    

    https://docs.djangoproject.com/en/dev/ref/contrib/comments/#redirecting-after-the-comment-post