开发者

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 %}>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜