简体   繁体   English

Django-registration和ReCaptcha集成 - 如何传递用户的IP

[英]Django-registration and ReCaptcha integration - how to pass the user's IP

New to django and trying to setup django-registration 0.8 with recaptcha-client. django的新手,并尝试使用recaptcha-client设置django-registration 0.8。 I followed the advice posted in the answer to this question . 我按照这个问题答案中的建议。

I used the custom form and custom backend from that post and the widget and field from this tutorial . 我使用了该帖子中的自定义表单和自定义后端以及本教程中的小部件和字段。 My form is displaying properly with the recaptcha widget but when I submit it throws the error about the missing IP. 我的表单正在使用recaptcha小部件正确显示,但是当我提交它时会抛出有关丢失的IP的错误。 What's the best way to pass the IP using django-registration? 使用django-registration传递IP的最佳方法是什么?

I also used the code from the tutorial you linked, in my case to add reCaptcha to the django comments app. 我还使用了你链接的教程中的代码,在我的例子中将reCaptcha添加到django评论应用程序。

You need something like initial={'captcha': request.META['REMOTE_ADDR']} at the point where your RecaptchaRegistrationForm gets instantiated. 在您的RecaptchaRegistrationForm实例化时,您需要类似initial={'captcha': request.META['REMOTE_ADDR']}的内容。

Unfortunately this is buried in the registration/views.py register method. 不幸的是,它隐藏在registration / views.py寄存器方法中。

You need to do something like copy and paste their code into a view method of your own and edit it. 您需要执行一些操作,例如将其代码复制并粘贴到您自己的视图方法中并进行编辑。 Then you need a urls.py for your customised backend that looks like the one in registration/backends/default/ but points to your new register view in place of theirs. 然后你需要一个urls.py用于你的自定义后端,它看起来像注册/后端/默认/但是指向你的新注册视图而不是他们的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM