Django: Redirect to same page after POST method using class based views

后端 未结 5 408
不思量自难忘°
不思量自难忘° 2020-12-28 14:05

I\'m making a Django app that keeps track of tv show episodes. This is for a page on a certain Show instance. When a user clicks to add/subtract a season, I want the page to

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 14:33

    I am guessing you need to provide a kwarg to identify the show when you redirect, although I can't see the code for your DetailView I would assume the kwarg is called either pk or possibly show going from the convention you've used in AddSeason and SubtractSeason. Try:

    redirect('show:detail', kwargs={'show': instance.pk})
    

    EDIT: the name of the detail url is 'show-detail', so the scoped viewname would be 'show:show-detail' (if it is in the show namespace like the other urls). I still think it would need a kwarg though, try:

    redirect('show:show-detail', kwargs={'show': instance.pk})
    

提交回复
热议问题