I am making a Django app that tracks episodes of TV shows. This page is for a specific instance of Show. When the user clicks to add / subtract the season, I want the page to redirect them to the same detailed view, right now I have an index that shows a list of all Show instances.
show-detail.html
<form action="{% url 'show:addseason' show=show %}" method="post"> {% csrf_token %} <button class="btn btn-default" type="submit">+</button> </form> <form action="{% url 'show:subtractseason' show=show %}" method="post"> {% csrf_token %} <button class="btn btn-default" type="submit">-</button> </form>
views.py
class ShowDetail(DetailView): model = Show slug_field = "title" slug_url_kwarg = "show" template_name = 'show/show-detail.html' class AddSeason(UpdateView): model = Show slug_field = 'title' slug_url_kwarg = 'show' fields = [] def form_valid(self, form): instance = form.save(commit=False) instance.season += 1 instance.save() return redirect('show:index') class SubtractSeason(UpdateView): model = Show slug_field = 'title' slug_url_kwarg = 'show' fields = [] def form_valid(self, form): instance = form.save(commit=False) if (instance.season >= 0): instance.season -= 1 else: instance.season = 0 instance.save() return redirect('show:index')
urls.py
url(r'^$', views.IndexView.as_view(), name='index'), url(r'^about/$', views.AboutView.as_view(), name='about'),
I get an error when I try
return redirect('show:detail')
This is mistake
NoReverseMatch at /Daredevil/addseason/ Reverse for 'detail' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
source share