Django comments: how to prevent form errors when redirecting a user to a preview page?

Currently, django.contrib.comments sends the user to the preview page if there is any error in the form.

I use comments in the context of the blog, and I would prefer the user to stay on the page they were on if something went wrong with the view. As far as I can tell, this is hardcoded in django.contrib.comments.views.comments.post_comment:

# If there are errors or if we requested a preview show the comment if form.errors or preview: template_list = [ "comments/%s_%s_preview.html" % tuple(str(model._meta).split(".")), "comments/%s_preview.html" % model._meta.app_label, "comments/preview.html", ] return render_to_response( template_list, { "comment" : form.data.get("comment", ""), "form" : form, "next": next, }, RequestContext(request, {}) ) 

Is there a way to change this behavior without changing the source code to django.contrib.comments?

Any pointer would be appreciated ...

Thanks!

+7
python django django-contrib
source share
2 answers

It looks like you have two real options:

  • Write your own look. Perhaps copy this view code to get started.
  • Fix the patch to view an additional parameter, for example, "preview_on_errors", which defaults to True, but can be overridden. Make the fix back in Django so that other people can benefit from it.
+3
source share

Yes! Now there is a way to customize the comments application . Good luck

0
source share

All Articles