Bioinfotec
Bioinfotec

Reputation: 93

How to drop email field in django-registartion?

I am using the third party app django-registration as my django project's registration system. I create the registration_form.htlm:

 <form method="post">
    {% csrf_token %}
    <h1 class="h3 mb-3 fw-normal">Sign up</h1>

    <div class="form-floating">
      <input
        class="form-control"
        id="floatingInput"
        placeholder="name"
        name="username"
      />
      <label for="floatingInput">User</label>
    </div>
    <div class="form-floating">
      <input class="form-control" placeholder="Email" name="email" />
      <label for="floatingPassword">Email</label>
    </div>
    <div class="form-floating">
      <input
        type="password"
        class="form-control"
        id="floatingPassword"
        placeholder="Password"
        name="password1"
      />
      <label for="floatingPassword">Password</label>
    </div>
    <div class="form-floating">
      <input
        type="password"
        class="form-control"
        id="floatingPassword"
        placeholder="Password"
        name="password2"
      />
      <label for="floatingPassword">Password</label>
    </div>

    <div class="checkbox mb-3">
      <label>
        <input type="checkbox" value="remember-me" /> Remember me
      </label>
    </div>
    <button class="w-100 btn btn-lg btn-primary" type="submit">
      Sign Up
    </button>
  </form>

And as you can see above, I have to specify the email or the form doesn't work. So is there any skill that to make the email completion optional, which means if a user doesn't provide email, the form can still be submitted successfully.

Upvotes: 0

Views: 40

Answers (1)

Gimbo
Gimbo

Reputation: 79

To make the email field optional in your registration form, you can modify the Django registration form and views to handle this scenario.

You will need to create a custom registration form that inherits from the original form provided by django-registration. You can override the field's required attribute to make the email field optional.

class CustomRegistrationForm(RegistrationForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['email'].required = False

Upvotes: 1

Related Questions