I am new in django. I have little bit confusion about reverse and redirect. In this forms if I replace my sucess url ‘return reverse’ to ‘return redirect’ then it will stop working. Why return redirect not working in this forms? when we should use return reverse and when we should use return redirect?
class BlogListMyAccount(LoginRequiredMixin,FormMixin,DetailView):
raise_exception = True
model = Blog
template_name = 'my-account-blog.html'
form_class = CommentFrom
def get_success_url(self):
return reverse('my-account-blog-details', kwargs={'slug': self.object.slug})
def get_context_data(self, **kwargs):
data = super(BlogListMyAccount, self).get_context_data(**kwargs)
data['filter'] = BlogComment.objects.filter(is_published="published")
data['my_forms'] = CommentFrom(initial={'blog': self.object})
return data
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
messages.add_message(self.request, messages.INFO, 'Your Comment pending for admin approval')
return self.form_valid(form)
else:
messages.add_message(self.request, messages.INFO, 'Somethings Wrong. Please resubmit your commnet')
return self.form_invalid(form)
def form_valid(self, form):
form.save()
return super(BlogListMyAccount, self).form_valid(form)