你好我试图将CommentForm子类化,我不确定我是否正确地做了。我正在隐藏这些字段,但它们没有那样渲染。
from django.contrib.comments.forms import CommentForm
from django import forms
from django.utils.translation import ungettext, ugettext_lazy as _
class customCommentForm(CommentForm):
name = forms.CharField(widget=forms.HiddenInput)
email = forms.EmailField(widget=forms.HiddenInput)
url = forms.URLField(widget=forms.HiddenInput)
comment = forms.CharField(label=_('Comment'), widget=forms.Textarea,
max_length=3000)
答案 0 :(得分:1)
这有点像黑客,但我最终在模板中用
这样做 {% ifequal field.name "name" %} style="display:none;"{% endifequal %}
{% ifequal field.name "email" %} style="display:none;"{% endifequal %}
{% ifequal field.name "url" %} style="display:none;"{% endifequal %}
{% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>