Created
January 11, 2018 09:53
-
-
Save k1000/a8702e93cae113994b2d17edbf1725ba to your computer and use it in GitHub Desktop.
Django HoneypotFormMixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
class HoneypotFormMixin(object): | |
"""Keep away spam bots trying to submit name""" | |
def __init__(self, *args, **kwargs): | |
super(HoneypotFormMixin, self).__init__(*args, **kwargs) | |
self.fields.update( | |
{"name": forms.CharField(required=False)} | |
) | |
def clean_name(self): | |
name = self.cleaned_data['name'] | |
if name: | |
raise forms.ValidationError("Dont put your name") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment