Django CBV CreateView - Redirect from CreateView to last page

前端 未结 1 1988
感情败类
感情败类 2021-01-24 15:16

I\'m learning Django and i have problem with redirecting back from CreateView I want to redirect to a BookDetail page which contains list of bookinstances which are created by C

1条回答
  •  粉色の甜心
    2021-01-24 15:32

    You need to define the get_success_url method, rather than the static success_url attribute:

    class BookInstanceCreate(PermissionRequiredMixin, CreateView):
        ...
        def get_success_url(self):
            return reverse('book-detail', kwargs={'pk': self.object.pk})
    

    0 讨论(0)
提交回复
热议问题