开发者

django form subclass for comments

开发者 https://www.devze.com 2023-01-16 15:13 出处:网络
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.

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

精彩评论

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