I want to create a simple message of “Your comment has been posted!” using Django’s messages framework. I am using Django’s comments framework and set it up so that after posting a comment it refreshes the page with
<div><input type="hidden" name="next" value="{{ request.get_full_path }}" /></div>
inside my form.html that I created to override the comments‘s default. I also had to include django.core.context_processors.request for TEMPLATE_CONTEXT_PROCESSORS inside my settings.py.
Anyway, the messages documentation says to add messages inside views.py. Does that means I need to override the comments‘s views.py or is there a simplier way to do this? I am a bit uncomfortable modifying the source code for comments. If I had to, I’m not even sure where to add the line
messages.add_message( request, messages.SUCCESS, 'You comment has been posted!' )
under def post_comment() in django.contrib.comments.views.comments.
You can connect a custom receiver to comment_was_posted signal. It can look like this:
A nice place for such a snippet is a project_specific models.py, because they are all imported at model definition time.