How do I extend UserCreationForm to include email field

前端 未结 3 1844
借酒劲吻你
借酒劲吻你 2021-01-12 01:26

I managed to get the stock standard User Creation Form to work. Which included just the username, password1 and password2 field. However, when I try to include the email fie

3条回答
  •  臣服心动
    2021-01-12 02:08

    forms.py

    from django.contrib.auth.forms import UserCreationForm
    from django.contrib.auth.models import User
    
    class SignupForm(UserCreationForm):
        class Meta:
            model = User
            fields = ("username", "email",)
    

    views.py

    from django.urls import reverse_lazy
    from django.views import generic
    from accounts.forms import SignupForm
    
    class SignUpView(generic.CreateView):
        form_class = SignupForm
        success_url = reverse_lazy('login')
        template_name = 'stories/register.html'
    

提交回复
热议问题