1π
β
The issue is with the line on your code "return redirect('forum/thread_list.html', id=forum)
"
The redirect function should be given a URL name, not a file path. In this case, the URL name is βthread_list
β, not βforum/thread_list.html
β.
The redirect function expects a URL name so you need to pass the id of the forum as an argument to the URL. Try this code if this works. Instead of "forum = thread.forum
" try "forum_id = thread.forum.id
" and then pass this "forum_id" to redirect "id=forum_id"
@login_required
def thread_delete(request, id):
thread = get_object_or_404(Thread, id=id)
forum_id = thread.forum.id
if request.method == 'POST':
thread.delete()
return redirect('thread_list', id=forum_id)
return render(request, 'forum/thread_delete.html', {'thread': thread})
π€dostogircse171
Source:stackexchange.com