[英]how to post a new comment through a method in django?
I am using 'django_comments' for commenting in my site. 我在网站上使用“ django_comments”发表评论。 Now i want to post a new comment via a method in my 'views.py'.
现在,我想通过“ views.py”中的方法发布新评论。
I searched and only found posting comments using {{ forms }} in templates. 我搜索并仅在模板中使用{{form}}找到了发表评论。
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.
您需要做的就是创建注释模型的实例,您可以通过Django的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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.