简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM