本文整理汇总了Python中captcha.fields.CaptchaField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.CaptchaField方法的具体用法?Python fields.CaptchaField怎么用?Python fields.CaptchaField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类captcha.fields
的用法示例。
在下文中一共展示了fields.CaptchaField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from captcha import fields [as 别名]
# 或者: from captcha.fields import CaptchaField [as 别名]
def __init__(self, target_object, data=None, initial=None, parent=None, **kwargs):
self.user = kwargs.pop('user', None)
self.parent = parent
if initial is None:
initial = {}
initial.update({'parent': self.parent})
super(MPTTCommentForm, self).__init__(target_object, data=data, initial=initial, **kwargs)
if self.user is not None:
if self.user.is_authenticated:
self.fields['email'].required = False
self.fields['name'].required = False
else:
self.fields['captcha'] = CaptchaField()
else:
current_request = CrequestMiddleware.get_request()
if current_request.user.is_authenticated:
self.fields['email'].required = False
self.fields['name'].required = False
else:
self.fields['captcha'] = CaptchaField()
示例2: get_captcha
# 需要导入模块: from captcha import fields [as 别名]
# 或者: from captcha.fields import CaptchaField [as 别名]
def get_captcha():
if getattr(settings, 'ENABLE_CAPTCHA', False):
if getattr(settings, 'RECAPTCHA_PRIVATE_KEY', '') and getattr(settings, 'RECAPTCHA_PUBLIC_KEY', ''):
from snowpenguin.django.recaptcha2.fields import ReCaptchaField
from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget
return ReCaptchaField(label='', widget=ReCaptchaWidget())
else:
from captcha.fields import CaptchaField
return CaptchaField(label='')
else:
return None