基于django simple math captcha的wagtail表单页的简单数学验证码字段。
wagtail-simple-math-captcha的Python项目详细描述
基于django simple math captcha的wagtail表单页的简单数学验证码字段。
wagtail simple math captcha提供了一种集成 django-simple-math-captcha 以摇摆的形式。代码基于 wagtailsweetcaptcha
安装
- 安装wagtail-simple-math-captcha。
- 将wagtailsimplemathcaptcha添加到 settings.py。
用法
当您安装wagtail-simple-math-captcha时,将无法获得验证码 表单生成器中可用字段类型中的字段。利用它你 需要对MathCaptchaForm或^{tt7}进行子类划分$ (替换AbstractForm和AbstractEmailForm 分别)。完成后,验证码字段将出现在 前端:
frommodelcluster.fieldsimportParentalKeyfromwagtail.wagtailadmin.edit_handlersimport(FieldPanel,InlinePanel,MultiFieldPanel)fromwagtail.wagtailcore.fieldsimportRichTextFieldfromwagtail.wagtailforms.modelsimportAbstractEmailForm,AbstractFormFieldfromwagtailsimplemathcaptcha.modelsimportMathCaptchaEmailFormclassFormField(AbstractFormField):page=ParentalKey('FormPage',related_name='form_fields')classFormPage(MathCaptchaEmailForm):intro=RichTextField(blank=True)thank_you_text=RichTextField(blank=True)# wagtail-simple-math-captcha configurationcaptcha_label=""captcha_help_text="Answer this question to prove you're human."FormPage.content_panels=[FieldPanel('title',classname="full title"),FieldPanel('intro',classname="full"),InlinePanel('form_fields',label="Form fields"),FieldPanel('thank_you_text',classname="full"),MultiFieldPanel([FieldPanel('to_address',classname="full"),FieldPanel('from_address',classname="full"),FieldPanel('subject',classname="full"),],"Email")]
可以配置字段的verbose_name和help_text 属性,包括captcha_label和captcha_help_text 类中的属性或重写get_captcha_label()和 get_captcha_help_text()方法:
frommodelcluster.fieldsimportParentalKeyfromwagtail.wagtailadmin.edit_handlersimport(FieldPanel,InlinePanel,MultiFieldPanel)fromwagtail.wagtailcore.fieldsimportRichTextFieldfromwagtail.wagtailforms.modelsimportAbstractEmailForm,AbstractFormFieldfromwagtailsimplemathcaptcha.modelsimportMathCaptchaEmailFormclassFormField(AbstractFormField):page=ParentalKey('FormPage',related_name='form_fields')classFormPage(MathCaptchaEmailForm):intro=RichTextField(blank=True)thank_you_text=RichTextField(blank=True)# wagtail-simple-math-captcha configurationdefget_captcha_label(self):return""defget_captcha_help_text(self):return"Answer this question to prove you're human."FormPage.content_panels=[FieldPanel('title',classname="full title"),FieldPanel('intro',classname="full"),InlinePanel('form_fields',label="Form fields"),FieldPanel('thank_you_text',classname="full"),MultiFieldPanel([FieldPanel('to_address',classname="full"),FieldPanel('from_address',classname="full"),FieldPanel('subject',classname="full"),],"Email")]
captcha_label和captcha_help_text的默认值都是 emty string公司。