【问题标题】:How clean_botcatcher(self): automatically called?clean_botcatcher(self): 怎么自动调用?
【发布时间】:2018-07-28 10:57:02
【问题描述】:

我很困惑,django 会自动调用 clean_botcatcher(self): 吗?它是否充当侦听器,当机器人对值进行更改时触发?

from django import forms
class FormName(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    text = forms.CharField(widget=forms.Textarea)
    botcatcher = forms.CharField(required=False,widget =forms.HiddenInput)

    def clean_botcatcher(self):
            botcatcher = self.cleaned_data['botcatcher']
            if len(botcatcher) > 0:
                raise forms.ValidationError("Gotcha BOT")
            return botcatcher

【问题讨论】:

    标签: django django-forms django-validation


    【解决方案1】:

    我假设您正在学习 Jose Portilla 的 udemy 课程?因为我刚刚浏览了这个确切的部分。我相信 FormName 类中的 def 函数会自动运行。他说如果表单中的值已被机器人更改,那么此函数将捕获机器人并为您提供验证错误。

    【讨论】:

    • 我假设这个过程是由 Django 自动完成的,其中 'clean_' 指定它在值更改时被触发。但是这实际上是如何工作的,我需要一些关于它是如何工作的参考资料。这种类型的调用有什么特殊的术语吗?
    猜你喜欢
    • 2012-04-09
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多