def comments(hash_id): paste = Paste.objects.get_or_404(hash_id=hash_id) form = CommentForm(request.form) if form.validate(): comment = Comment(user=current_user.user, paste=paste, content=form.content.data) comment.save() if comment.user != paste.user: content = NEW_COMMENT.format( user_username=current_user.user.username, user_url=url_for('user_app.view', username=current_user.user.username), paste_title=paste.title, paste_url=url_for('paste_app.view_paste', hash_id=paste.hash_id)) message = Message(user=paste.user, who=current_user.user, content=content) message.save() return redirect(url_for('paste_app.view_paste', hash_id=hash_id))