我试图禁止从一个单一的ip重复注册。这是我的密码。你知道吗
class SignupForm(forms.Form):
def signup(self, request, user):
ip = get_client_ip(request)
if UserProfile.objects.filter(registration_ip=ip).exists():
self.add_error(
None, "You cannot register more than one account from the same IP")
else:
user.userprofile.registration_ip = ip
user.userprofile.save()
user.save()
当前,当一个用户注册时与另一个注册用户具有相同的ip,表单仍然有效。我需要表单返回一个错误。有人能帮忙吗?提前谢谢。你知道吗
(上面的代码重写了django allauth包的SignupForm)
if语句工作正常。一开始我尝试使用raise ValidationError
,效果很好,但这对用户体验不好。我需要表单失效,并返回我的自定义错误的表单页。你知道吗
使用清洁功能:
该过滤返回一个istance,它不检查IP是否相同,也不检查IP是否存在。
首先,您需要通过模型生成uniqe
registration_ip
。然后可以通过如下形式使用
clean
方法:相关问题 更多 >
编程相关推荐