Returning to the Object with Django Comments

If you are using django.contrib.comments for your project, it may not be immediately obvious how to get back to the page the comment was posted from. The user gets left at a "Thank you for your comment" message.

However, the comment object returns a comment specific URL with its get_absolute_url() method. If you have defined get_absolute_url() on your object, the comment URL will effectively redirect to your object's URL. It even passes along an anchor in the form of #c[comment_id] so you can automatically scroll right to the comment!

Since the posted.html template that renders the thank you message already has access to the comment object, one easy way to get the user back where they came from is to override this template by copying it to your template directory and add in a link back to the object:

templates/comments/posted.html

1
2
3
4
{% block content %}
    <h1>{% trans "Thank you for your comment" %}.</h1>
    <a href="{{ comment.get_absolute_url }}">Return to blog entry</a>
{% endblock %}

Comments

reStructuredText is supported.