django rest recaptcha字段,便于将google recaptcha与django rest框架集成。
django-rest-recaptcha的Python项目详细描述
张江县张江县rest recaptcha-rest-recaptcha
=
=
=
=
**d江县rest recaptcha域在张江县rest框架中添加google recaptcha的d江县rest recaptcha域在张江县rest框架中添加google recaptcha**
>
>
>
>
>测试。使用“pip install django rest recaptcha”安装。
。将“recaptcha”添加到“已安装的应用程序”设置中。在这里注册并获取recaptcha密钥`https://www.google.com/recaptcha/admin`
\将获得的密钥添加到设置中(对于测试和开发,您可以将其留空以使用此处提到的默认测试密钥“https://developers.google.com/recaptcha/docs/faq”。
例如:
代码块::python
gr_captcha_secret_key='googlerecaptchaprivatekey001'
用法
----
现在您可以导入并使用序列化程序中的reCAPTCHA字段。
例如:
…代码块::python
from rest_framework import serializer
from recaptcha.fields import recaptchafield
class exampleSerializer(serializer.serializer):
recaptcha=recaptchafield(write_only=true)
…
unit testing
~环境变量“recaptcha_testing”有助于测试。在
测试环境中,此环境变量应设置为“true”,任何值都将被视为已验证。
示例:
。代码块::python
import os
os.environ['recaptcha_testing']=“true”
data={'recaptcha':'dummy value'}
response=client.post('/my/api/endpoint/',data)
assert response.status_code==200
=
=
=
=
**d江县rest recaptcha域在张江县rest框架中添加google recaptcha的d江县rest recaptcha域在张江县rest框架中添加google recaptcha**
>
>
>
>
>测试。使用“pip install django rest recaptcha”安装。
。将“recaptcha”添加到“已安装的应用程序”设置中。在这里注册并获取recaptcha密钥`https://www.google.com/recaptcha/admin`
\将获得的密钥添加到设置中(对于测试和开发,您可以将其留空以使用此处提到的默认测试密钥“https://developers.google.com/recaptcha/docs/faq”。
例如:
代码块::python
gr_captcha_secret_key='googlerecaptchaprivatekey001'
用法
----
现在您可以导入并使用序列化程序中的reCAPTCHA字段。
例如:
…代码块::python
from rest_framework import serializer
from recaptcha.fields import recaptchafield
class exampleSerializer(serializer.serializer):
recaptcha=recaptchafield(write_only=true)
…
unit testing
~环境变量“recaptcha_testing”有助于测试。在
测试环境中,此环境变量应设置为“true”,任何值都将被视为已验证。
示例:
。代码块::python
import os
os.environ['recaptcha_testing']=“true”
data={'recaptcha':'dummy value'}
response=client.post('/my/api/endpoint/',data)
assert response.status_code==200