易于使用的 django 验证码或带有验证码的注册应用程序?

发布于 2024-08-21 18:12:26 字数 1803 浏览 3 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奢欲 2024-08-28 18:12:26

django-registration 是相当可扩展的。扩展它的一种方法是提供自定义注册表单。我建议使用 reCaptcha,例如来自 此处 (已存档)。然后就像编写自定义表单类和注册后端一样简单(这比听起来更简单):

from registration.backends.default import DefaultBackend
from registration.forms import RegistrationForm

class RecaptchaRegistrationForm(RegistrationForm)
    recaptcha = ReCaptchaField(label="I'm a human")

class RecaptchaRegistrationBackend(DefaultBackend):
    def get_form_class(self, request):
        return RecaptchaRegistrationForm

最后一步是告诉 django-registration 使用您的后端。 文档 (抱歉,我找不到该文档的 HTML 版本)

django-registration is pretty extendable. One way to extend it is to provide a custom registration form. I'd recommend to use reCaptcha, e.g. with the widget and form field from here (archived). Then it is as simple as writing a custom form class and registration backend (which is simpler than it sounds):

from registration.backends.default import DefaultBackend
from registration.forms import RegistrationForm

class RecaptchaRegistrationForm(RegistrationForm)
    recaptcha = ReCaptchaField(label="I'm a human")

class RecaptchaRegistrationBackend(DefaultBackend):
    def get_form_class(self, request):
        return RecaptchaRegistrationForm

The last step is to tell django-registration to use your backend. That step is described in the docs (I couldn't find a HTML version of the docs, sorry)

咿呀咿呀哟 2024-08-28 18:12:26

我刚刚遇到了这个问题,但解决方案非常简单。

我正在使用 django-registration,并且我想要一个用于用户注册的 reCAPTCHA 字段。只需 1 分钟:

  1. 下载 django-recaptcha (pip install django-recaptcha )

  2. 将其安装到您的项目中。也就是说,将“captcha”文件夹复制到您的项目中,将“captcha”添加到 INSTALLED_APPS 中,并将 RECAPTCHA_PUBLIC_KEYRECAPTCHA_PRIVATE_KEY 密钥添加到设置中。 py 也(如安装说明中所述)

  3. 打开 registration/forms.py 并在 class RegistrationForm(forms.Form):

    中添加此字段

    验证码 = ReCaptchaField()

    您还必须导入:

    from captcha.fields import ReCaptchaField

就是这样。不到一分钟。

I've just had this problem, but the solution is dead simple.

I'm using django-registration, and I want a reCAPTCHA field for user registration. In just 1 minute:

  1. download django-recaptcha (pip install django-recaptcha)

  2. install it on your project. That is, copy the "captcha" folder to your project, add "captcha" to INSTALLED_APPS and add your RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY keys to settings.py too (as described in the installation instructions)

  3. open registration/forms.py and add this field inside class RegistrationForm(forms.Form):

    captcha = ReCaptchaField()

    you will also have to import:

    from captcha.fields import ReCaptchaField

And that's it. Less than a minute.

月光色 2024-08-28 18:12:26

对于像我这样迟到的人来说,现在有很多解决方案,它们非常容易安装:

我已经成功设置了 Django Mollom 和 Django Simple Captcha,最困难的部分是在我的 Mac 上安装 PIL 的过程。实现代码就像每个文档所建议的那样简单。

For those like me arriving late to the thread, there are a bunch of solutions out there now, which are pretty easy to install:

I've successfully setup Django Mollom and Django Simple Captcha, and the hardest part was yak shaving around installing PIL on my Mac. Implementing the code was as straightforward as the docs for each would suggest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文