pythondjangodjango-viewsdjango-comments

how to post a new comment through a method in django?


I am using 'django_comments' for commenting in my site. Now i want to post a new comment via a method in my 'views.py'.

I searched and only found posting comments using {{ forms }} in templates.

So how can i post a new comment through a method. Please help me.. and thanks in advance.


Solution

  • You don't have to use a form, or a post request for that matter. All you need to do is create an instance of the comment model which you can do via Django's ORM.

    To do this, you would need to have all of the necessary parameters the model expects, but it's as simple as:

    comment = Comment.objects.create(**params)