基于 Django 简单数学验证码的 Wagtail 表单页面的简单数学验证码字段。
项目描述
基于 Django 简单数学验证码的 Wagtail 表单页面的简单数学验证码字段。
wagtail-simple-math-captcha 提供了一种以 Wagtail 形式集成 django-simple-math-captcha的方法 。该代码基于 wagtailsweetaptcha
安装
安装wagtail-simple-math-captcha。
将wagtailsimplemathcaptcha添加到您的 settings.py中的INSTALLED_APPS中。
用法
当您安装wagtail-simple-math-captcha时,您不会在表单构建器的可用字段类型中获得验证码字段。要使用它,您需要继承 MathCaptchaForm或MathCaptchaEmailForm (分别替换AbstractForm和AbstractEmailForm )。完成后,验证码字段将出现在您的前端:
from modelcluster.fields import ParentalKey
from wagtail.wagtailadmin.edit_handlers import (FieldPanel, InlinePanel,
MultiFieldPanel)
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
from wagtailsimplemathcaptcha.models import MathCaptchaEmailForm
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='form_fields')
class FormPage(MathCaptchaEmailForm):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
# wagtail-simple-math-captcha configuration
captcha_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")
]
您可以通过在类中包含captcha_label和captcha_help_text 属性或覆盖get_captcha_label()和 get_captcha_help_text()方法来配置字段的verbose_name和help_text 属性:
from modelcluster.fields import ParentalKey
from wagtail.wagtailadmin.edit_handlers import (FieldPanel, InlinePanel,
MultiFieldPanel)
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
from wagtailsimplemathcaptcha.models import MathCaptchaEmailForm
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='form_fields')
class FormPage(MathCaptchaEmailForm):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
# wagtail-simple-math-captcha configuration
def get_captcha_label(self):
return ""
def get_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的默认值都是空字符串。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
wagtail-simple-math-captcha-0.1.2.zip
(10.7 kB
查看哈希)
关
wagtail-simple-math-captcha-0.1.2.zip的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 6352512b5eeed02da060181e3503cb4092c87512acd9caa931ec94d840463b75 |
|
| MD5 | 88a535cac10840514abe7a2f619c4306 |
|
| 布莱克2-256 | 961ca7f5b87247bd9f46da3aa1991a8712d40e794dfe6bb3f59705273c4f47d4 |