When I type the slug in to the url I can see the detail view of that post however, I can't redirect to the newly formed post when it saves into db. The post's are getting saved but on the redirect I keep getting NoReverseMatch Error.
Reverse for 'question_detail' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'(?i)question/(?P<slug>[\w\\-]+)/$']
I can't seem to crack it.
questions-url.py:
url(r'^(?P<slug>[\w\-]+)/$', QuestionDetailView.as_view(), name='question_detail')
views- redirect (after form saved) :
return reverse('questions:question_detail')
views - detail view
class QuestionDetailView(DetailView):
template_name = "questions/question_detail.html"
model = Question
slug_url_kwarg = 'slug'
models.py
def get_absolute_url(self):
return reverse('questions:question_detail', kwargs={'slug':self.slug, 'question_id':self.id})
As the error says, the question_detail pattern expects a slug parameter but you are not passing one. You do so in your get_absolute_url method; you should do the same in your view.