ビューの Timmy のコード フラグメントにはまだ 1 つのインポート ステートメントがなく、応答が返されませんでした。これは同じコードで、現在は外部の django_comments アプリ (django 1.6+) に更新されています。
from django.shortcuts import get_object_or_404
import django.http as http
from django_comments.views.moderation import perform_delete
from django_comments.models import Comment
def delete_own_comment(request, id):
comment = get_object_or_404(Comment, id=id)
if comment.user.id != request.user.id:
raise Http404
perform_delete(request, comment)
return http.HttpResponseRedirect(comment.content_object.get_absolute_url())
これにより、メッセージなしで元のページにリダイレクトされます (ただし、おそらくコメントが 1 つ少なくなります)。
このビューの URL を登録します。
url(r'^comments/delete_own/(?P<id>.*)/$', delete_own_comment, name='delete_own_comment'),
そして、comments/list.html を直接変更して、以下を含めます。
{% if user.is_authenticated and comment.user == user %}
<a href="{% url 'delete_own_comment' comment.id %}">--delete this comment--</a>
{% endif %}