本文整理匯總了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