thesteve
thesteve

Reputation: 2503

Django class based views success_url

I am trying to set the success_url on a django class based UpdateView but cannot get it to work. I have tried the syntax suggested in the docs

success_url="/polls/%(slug)s/"

But it is not working. How can I access the model fields in the success_url?

Upvotes: 1

Views: 3118

Answers (1)

mkriheli
mkriheli

Reputation: 1846

This relies on object field attributes. In the example you've posted, the model should have a slug field.

For related fields:

You can try using django's __ notation for related objects (e.g: user__username) in success_url, not sure if it'll work.

IMO in such cases a better practice is overriding get_success_url(), and returning the url taking into account self.object.

Upvotes: 5

Related Questions