django form subclass for comments
hello im trying to subclass the CommentForm, and I'm not sure if I'm doing it correctly. I'm making those fields hidden开发者_如何转开发, but they aren't rendering that way.
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)
It is a bit of a hack, but I ending up doing this in the template with something like
{% 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 %}>
精彩评论