Package: django-recaptcha429
Django reCAPTCHADjango reCAPTCHA form field/widget integration app.ContentsDjango reCAPTCHARequirementsInstallationUsageFieldsWidgetsreCAPTCHA v3 ScoreLocal Development and Functional TestingCreditsAuthorsCurrent MaintainerPraekelt ConsultingbTaylor DesignOtherChangelog2.1.02.0.62.0.52.0.42.0.32.0.22.0.12.0.01.5.0 (2019-01-09)1.4.0 (2018-02-08)1.3.1 (2017-06-27)1.3.0 (2017-04-10)1.2.1 (2017-01-23)1.2.0 (2016-12-19)1.1.0 (2016-10-28)1.0.6 (2016-10-05)1.0.5 (2016-01-04)1.0.4 (2015-04-16)1.0.3 (2015-01-13)1.0.2 (2014-09-16)1.0.1 (2014-09-11)1.0 (2014-04-23)0.0.9 (2014-02-14)0.0.8 (2014-02-13)0.0.7 (2014-02-12)0.0.6 (2013-01-31)0.0.5 (2013-01-17)0.0.40.0.3 (2011-09-20)0.0.2 (2011-08-10)0.0.1 (2010-06-17)Notedjango-recaptcha supports Google reCAPTCHA V2 - Checkbox (Default), Google reCAPTCHA V2 - Invisible and Google reCAPTCHA V3 please look at the widgets section for more information.Django reCAPTCHA uses a modified version of thePython reCAPTCHA clientwhich is included in the package asclient.py.RequirementsTested with:Python: 3.7, 3.8, 3.9, 3.10Django: 2.2, 3.2, 4.0You can view thePython-Django support matrix hereInstallationSign up for reCAPTCHA.Install withpip installdjango-recaptcha429.Add'captcha'to yourINSTALLED_APPSsetting.INSTALLED_APPS=[...,'captcha',...]Add the Google reCAPTCHA keys generated in step 1 to your Django production settings withRECAPTCHA_PUBLIC_KEYandRECAPTCHA_PRIVATE_KEY. Note that omitting these settings will default to a set of test keys refer toLocal Development and Functional Testingfor more information.For example:RECAPTCHA_PUBLIC_KEY='MyRecaptchaKey123'RECAPTCHA_PRIVATE_KEY='MyRecaptchaPrivateKey456'These can also be specified per field by passing thepublic_keyorprivate_keyparameters toReCaptchaField- see field usage below.(OPTIONAL) If you require a proxy, add aRECAPTCHA_PROXYsetting (dictionary of proxies), for example:RECAPTCHA_PROXY={'http':'http://127.0.0.1:8000','https':'https://127.0.0.1:8000'}(OPTIONAL) In the eventwww.google.comis not accessible theRECAPTCHA_DOMAINsetting can be changed towww.recaptcha.netas per thereCAPTCHA FAQ:RECAPTCHA_DOMAIN='www.recaptcha.net'This will change the Google JavaScript api domain as well as the client side field verification domain.UsageFieldsThe quickest way to add reCAPTCHA to a form is to use the includedReCaptchaFieldfield class. AReCaptchaV2Checkboxwill be rendered by default. For example:fromdjangoimportformsfromcaptcha.fieldsimportReCaptchaFieldclassFormWithCaptcha(forms.Form):captcha=ReCaptchaField()Be sure to include the captcha field in your forms. There are many ways to add fields to forms in Django. We recommend you refer to theform rendering optionsandrendering fields manuallysections of theofficial Django documentation for forms.To allow for runtime specification of keys you can optionally pass theprivate_keyorpublic_keyparameters to the constructor. For example:captcha=ReCaptchaField(public_key='76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh',private_key='98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs',)If specified, these parameters will be used instead of your reCAPTCHA project settings.WidgetsThere are three widgets that can be used with theReCaptchaFieldclass:ReCaptchaV2CheckboxforGoogle reCAPTCHA V2 - CheckboxReCaptchaV2InvisibleforGoogle reCAPTCHA V2 - InvisibleReCaptchaV3forGoogle reCAPTCHA V3To make use of widgets other than the default Google reCAPTCHA V2 - Checkbox widget, simply replace theReCaptchaFieldwidget. For example:fromdjangoimportformsfromcaptcha.fieldsimportReCaptchaFieldfromcaptcha.widgetsimportReCaptchaV2InvisibleclassFormWithCaptcha(forms.Form):captcha=ReCaptchaField(widget=ReCaptchaV2Invisible)The reCAPTCHA widget supports severaldata attributesthat
customize the behaviour of the widget, such asdata-theme,data-size, etc. You can
forward these options to the widget by passing anattrsparameter to the
widget, containing a dictionary of options. For example:captcha=fields.ReCaptchaField(widget=widgets.ReCaptchaV2Checkbox(attrs={'data-theme':'dark','data-size':'compact',}))# The ReCaptchaV2Invisible widget# ignores the "data-size" attribute in favor of 'data-size="invisible"'The reCAPTCHA api supports severalparameters. To customise
the parameters that get sent along pass anapi_paramsparamater to the
widget, containing a dictionary of options. For example:captcha=fields.ReCaptchaField(widget=widgets.ReCaptchaV2Checkbox(api_params={'hl':'cl','onload':'onLoadFunc'}))# The dictionary is urlencoded and appended to the reCAPTCHA api url.By default, the widgets provided only supports a single form with a single widget on each page.The language can be set with the ‘h1’ parameter, look atlanguage codesfor the language code options. Note that translations need to be added to this package for the errors to be shown correctly. Currently the package has error translations for the following language codes: es, fr, nl, pl, pt_BR, ru, zh_CN, zh_TWHowever, the JavaScript used by the widgets can easily be overridden in the templates.The templates are located in:captcha/includes/js_v2_checkbox.htmlfor overriding the reCAPTCHA V2 - Checkbox templatecaptcha/includes/js_v2_invisible.htmlfor overriding the reCAPTCHA V2 - Invisible templatecaptcha/includes/js_v3.htmlfor overriding the reCAPTCHA V3 templateFor more information about overriding templates look atDjango’s template overridereCAPTCHA v3 ScoreAs of version 3, reCAPTCHA also returns a score value. This can be used to determine the likelihood of the page interaction being a bot. See the Googledocumentationfor more details.To set a project wide score limit use theRECAPTCHA_REQUIRED_SCOREsetting.For example:RECAPTCHA_REQUIRED_SCORE=0.85For per field, runtime, specification the attribute can also be passed to the widget:captcha=fields.ReCaptchaField(widget=ReCaptchaV3(attrs={'required_score':0.85,...}))In the event the score does not meet the requirements, the field validation will fail as expected and an error message will be logged.Local Development and Functional TestingGoogle provides test keys which are set as the default forRECAPTCHA_PUBLIC_KEYandRECAPTCHA_PRIVATE_KEY. These cannot be used in production since they always validate to true and a warning will be shown on the reCAPTCHA.To bypass the security check that prevents the test keys from being used unknowingly addSILENCED_SYSTEM_CHECKS =[...,'captcha.recaptcha_test_key_error',...]to your settings, here is an example:SILENCED_SYSTEM_CHECKS=['captcha.recaptcha_test_key_error']CreditsCurrent Maintainer isAndrew Chen WangOriginally developed byPraekelt ConsultingInspired Marco Fucci’s blogpost titledIntegrating reCAPTCHA with Djangoclient.pytaken fromrecaptcha-clientlicenced MIT/X11 by Mike
Crawford.reCAPTCHA copyright 2012 Google.AuthorsCurrent MaintainerAndrew Chen WangPraekelt ConsultingShaun SephtonPeter PistoriusHedley RoosAltus BarryCilliers BlignautbTaylor DesignBrandon TaylorOtherBrooks TravisDenis MishchishinJoshua PeperRodrigo PrimosnnwolfAdriano Oriolicdvv7788Daniel Gatis CarrazzonipbfAlexey SubbotinSean StewartRob CharlwoodChangelog2.1.0Added testing for Django 3.2 and 4.0Removed support for Django 1.11 and Python 2Removed upper Django dependency constraint2.0.6Added testing for Django 3 (no code changes needed).2.0.5Added settings and kwargs that allow for the validation of reCAPTCHA v3 score values.2.0.4Fixed travis tests for django 2.22.0.3Added testing for Django 2.2 (no code changes needed).2.0.2Moved field based Google dev key check to an app ready registered security check.2.0.1Bugfix: Remove extra div in widget_v3 template2.0.0ReCAPTCHA v3 support added.Remove all mention of the V1 reCAPTCHA endpoint.Refactor client, fields and widgets code.Added widgets for each type of reCAPTCHA:V2 Checkbox,V2 Invisible,V3Remove the need for the widget template to be selected based on certain settings values, each widget has its own template.Introduced a large number of new unit tests, update tests to make use of tox venvs.Regenerated po and mo files.1.5.0 (2019-01-09)Added testing for Django 2.1 (no code changes needed).Update the unit tests to no longer make use of reCAPTCHA v1.Added deprecation warnings for reCAPTCHA v1 support.Remove the need for RECAPTCHA_TESTING environment variable during unit testing.Added Invisible reCAPTCHA V2 support.1.4.0 (2018-02-08)Dropped support for Django < 1.11.Added testing for Django 2.0 (no code changes needed).1.3.1 (2017-06-27)Fixed widget attributes regression for Django < 1.10.1.3.0 (2017-04-10)Support Django 1.11 in addition to 1.8, 1.9, and 1.10.1.2.1 (2017-01-23)Made reCAPTCHA test keys the default keys for easy use in development. The
captcha doesn’t require any interaction, has a warning label that it’s for
testing purposes only, and always validates.1.2.0 (2016-12-19)Pass options as HTML data attributes instead of theRecaptchaOptionsJavaScript object in the default template. Custom templates usingRecaptchaOptionsshould migrate to using HTML data attributes.1.1.0 (2016-10-28)Dropped support for old Django versions. Only the upstream supported
versions are now supported, currently 1.8, 1.9, and 1.10.Made recaptcha checking use SSL by default. This can be disabled by settingRECAPTCHA_USE_SSL = Falsein your Django settings or passinguse_ssl=Falseto the constructor ofReCaptchaField.Made ReCaptchaField respect required=False1.0.6 (2016-10-05)Confirmed tests pass on Django 1.10. Older versions should still work.Fixed a bug where the widget was always rendered in the first used language
due toattrsbeing a mutable default argument.1.0.5 (2016-01-04)Chinese translation (kz26).Syntax fix (zvin).Get tests to pass on Django 1.9.1.0.4 (2015-04-16)Fixed Python 3 supportAdded Polish translationsUpdate docs1.0.3 (2015-01-13)Added nocaptcha recaptcha support1.0.2 (2014-09-16)Fixed Russian translationsAdded Spanish translations1.0.1 (2014-09-11)Added Django 1.7 suportAdded Russian translationsAdded multi dependancy supportCleanup1.0 (2014-04-23)Added Python 3 supportAdded French, Dutch and Brazilian Portuguese translations0.0.9 (2014-02-14)Bugfix: release master and not develop. This should fix the confusion due to master having been the default branch on Github.0.0.8 (2014-02-13)Bugfix: remove reference to options.html.0.0.7 (2014-02-12)Make it possible to load the widget via ajax.0.0.6 (2013-01-31)Added an extra parameterlangto bypass Google’s language bug. Seehttp://code.google.com/p/recaptcha/issues/detail?id=133#c3widget.html no longer includes options.html. Options are added directly to widget.html0.0.5 (2013-01-17)Removed django-registration dependencyChanged testing mechanism to environmental variableRECAPTCHA_TESTING0.0.4Handle missing REMOTE_ADDR request meta key. Thanks Joe Jasinski.Added checks for settings.DEBUG to facilitate tests. Thanks Victor Neo.Fix for correct iframe URL in case of no javascript. Thanks gerdemb.0.0.3 (2011-09-20)Don’t force registration version thanks kshileev.Render widget using template, thanks denz.0.0.2 (2011-08-10)Use remote IP when validating.Added SSL support, thanks Brooks Travis.Added support for Javascript reCAPTCHA widget options, thanks Brandon Taylor.Allow for key and ssl specification at runtime, thanks Evgeny Fadeev.0.0.1 (2010-06-17)Initial release.