3

How do I remove the email field from Django allauth signup? No settings here show any option to remove it.

Any idea?

EDIT: My custom form:

class AllauthSignupForm(forms.Form):

    captcha = ReCaptchaField()

    class Meta:
        model = User
        fields = ('username', 'password1', 'password2')

    def signup(self, request, user):
        """ Required, or else it throws deprecation warnings """
        pass

settings.py

ACCOUNT_SIGNUP_FORM_CLASS = 'draft1.forms.AllauthSignupForm'
Zorgan
  • 8,227
  • 23
  • 106
  • 207
  • ACCOUNT_EMAIL_REQUIRED (=False) what about this ? – Vikas Periyadath Apr 02 '18 at 09:31
  • I've done `ACCOUNT_EMAIL_REQUIRED = False` but it still doesn't remove the email field from signup form (default is `False` anyway) – Zorgan Apr 02 '18 at 09:34
  • Possible duplicate of [How to customize user profile when using django-allauth](https://stackoverflow.com/questions/12303478/how-to-customize-user-profile-when-using-django-allauth) – Dušan Maďar Apr 02 '18 at 09:53

3 Answers3

0

Try this: inn your settings.pyadd

ACCOUNT_USER_MODEL_EMAIL_FIELD = None
ACCOUNT_EMAIL_REQUIRED = False

Then you might also want to add this if you want the user to log in with username

ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'username'

Alternatively:

ACCOUNT_SIGNUP_FORM_CLASS='yourcustomform'

And the form

class YourCustomForm(UserCreationForm):

class Meta:
    model = User
    fields = ('username', 'password1', 'password2', ...)
Olaf Górski
  • 166
  • 5
  • Still doesn't remove the email field from the signup form – Zorgan Apr 02 '18 at 09:42
  • Weird I added alternative solution – Olaf Górski Apr 02 '18 at 09:49
  • Ah my mistake, I was using a custom form. However, when I remove `email` from my fields in the custom form it still doesn't remove the email field. I've added the code in my edit if you'd like to look. – Zorgan Apr 02 '18 at 09:55
  • [Isn't this thread similar to what you are describing?](https://stackoverflow.com/questions/12303478/how-to-customize-user-profile-when-using-django-allauth?noredirect=1&lq=1) – Olaf Górski Apr 02 '18 at 16:54
0

Did you try to exclude the email field?

class AllauthSignupForm(forms.Form):
    captcha = ReCaptchaField()

    class Meta:
        model = User
        fields = ('username', 'password1', 'password2')
        exclude = ('email',)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields.pop('email')

    def signup(self, request, user):
        """ Required, or else it throws deprecation warnings """
        pass
Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
0

I've had the same problem, so I went to External Libraries/site-packages/allauth/account/forms.py and commented out lines 300-314 and 266-269. Try it out :)