success_url in UpdateView, based on passed value

Create a class MyUpdateView inheritted from UpdateView and override get_success_url method:

class MyUpdateView(UpdateView):
    def get_success_url(self):
        pass #return the appropriate success url

Also i like to pass such parameters like template_name and model inside of inheritted class view, but not in .as_view() in urls.py


Had the same issue. Was able to get the paramater from self.kwargs as Dima mentioned:

def get_success_url(self):
        if 'slug' in self.kwargs:
            slug = self.kwargs['slug']
        else:
            slug = 'demo'
        return reverse('app_upload', kwargs={'pk': self._id, 'slug': slug})

I found a way which is useful and very simple. Check it out.

class EmployerUpdateView(UpdateView):
        model = Employer
        #other stuff.... to be specified

        def get_success_url(self):
           pk = self.kwargs["pk"]
           return reverse("view-employer", kwargs={"pk": pk})