我正在尝试自定义 Django 的评论表单。在里面django.contrib.comments.forms
我注意到所有的字段形式都是在类中声明的CommentDetailForm
,它是继承自CommentSecurityForm
. 然后我想当我写模板标签{% get_comment_form for order as form %}
时,它会得到一个类CommentForm
,它继承CommentDetailForm
了一个蜜罐字段。
我想自定义评论表单,使它只显示评论字段(而不是可选的名称、电子邮件或 URL 字段)。这些信息将由当前登录的用户提供。实际上,只有特定UserProfile.user_type
(UserProfile
具有外键User
)的登录用户才允许发表评论。
关于如何实现这一目标的任何提示?查看 Django 评论的源代码已经吓到我了,哈哈。
编辑:
到目前为止,评论模板的外观如下:
{% get_comment_form for order as form %}
<form action = "{% comment_form_target %}" method = "post">
{% csrf_token %}
{{ form }}
<input type = "submit" name = "submit" value = "Post">
</form>
该网站看起来像这样
我想隐藏Name
,Email address
和URL
。