[SOLVED] reverse_lazy not redirecting to the correct link (adding a suffix)


This Content is from Stack Overflow. Question asked by Ayat Rahman

so this is my class based function

class AddCommentView(CreateView):
model = Comment

form_class = CommentForm
template_name = 'app/add_comment.html'
def form_valid(self, form):
list_obj = List.objects.get(slug = self.kwargs['slug'])
        form.instance.list = list_obj
return super().form_valid(form)

success_url = reverse_lazy("app:list_detail", kwargs={'slug': List.slug})

once the comment is submitted I wanna go back to detailview page which is

but its taking me to

any way i can solve this?

in my urls

(I have excluded irrelevant paths)

app_name = "app"
urlpatterns = [
path('', views.HomeView.as_view(),name='home'),
path('list/<slug:slug>/', TheirDetailView.as_view(),name='list_detail'),


Try to change success_url = reverse_lazy("app:list_detail", kwargs={'slug': List.slug}) to success_url = reverse_lazy("app:list_detail", kwargs={'slug': list_obj.slug}).
You should use the variable name, not the Model

This Question was asked in StackOverflow by Ayat Rahman and Answered by Giorgio Scarso It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?