Есть реализация добавления и удаления комментариев. Но они выводятся только на странице 'comments.html' а когда пытаюсь вывести на странице 'topic_detail.html' появляется ошибка 'NoReverseMatch at /reply/1
Reverse for 'like_topic' with arguments '('',)' not found. 2 pattern(s) tried: ['like_topic/(?P[0-9]+)(?P\\.[a-z0-9]+/?)\\Z', 'like_topic/(?P[0-9]+)/\\Z']'
Код:
views.py
def reply_topic(request, pk):
topic = get_object_or_404(Topic, id=pk)
reply = Reply.objects.filter(topic=pk)
if request.method == 'POST':
form = ReplyForm(request.POST)
if form.is_valid():
form = form.save(commit=False)
form.user = request.user
form.topic = topic
form.save()
return redirect('forum:reply_topic', pk)
else:
form = ReplyForm()
# return render(request, 'forum/comments.html', {'form': form, 'comments': reply, 'topic': topic})
return render(request, 'forum/topic_detail.html', {'form': form, 'comments': reply, 'topic': topic})
def to_get_reply(request, id):
selected_reply = get_object_or_404(Reply, id=id)
selected_reply.delete()
return redirect('forum:reply_topic', id)
models.py
class Reply(models.Model):
author = models.EmailField()
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, related_name='comment_set', blank=True)
content = models.TextField(max_length=200)
topic = models.ForeignKey(Topic, on_delete=models.CASCADE, related_name='topic_set')
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='parent_set', blank=True, null=True)
objects = models.Manager()
class Meta:
verbose_name = _('Reply')
verbose_name_plural = _('Replies')
ordering = ('-id',)
# def __str__(self):
# return '{author}: {topic}'.format(author=self.author, topic=self.topic.name)
def __str__(self):
return self.content
urls.py
path('like_topic/<int:id>/', like_topic, name='like_topic'),
path('reply/<int:pk>', views.reply_topic, name='reply_topic'),
path('reply_remove/<int:id>', views.to_get_reply, name='delete_reply'),
При добавлении строчки кода :
return render(request, 'forum/topic_detail.html', {'form': form, 'comments': reply, 'topic': topic})
Возникает ошибка NoReverseMatch с ссылкой на страницу лайков.
<form action="{% url 'forum:like_topic' object.id %}" method="post">