简体   繁体   中英

I can't store first , last name and email in django admin panel

forms.py this is my form

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Profile

class UserSignUpForm(UserCreationForm):
    email = forms.EmailField()
    first_name = forms.CharField(max_length=50)
    last_name = forms.CharField(max_length=50)

    class Mate :
        model = User
        fields = ['username' , 'email' , 'first_name' , 'last_name' ,'password1' , 'password2']

views.py this is the Sign-Up Function

from django.shortcuts import render , redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserSignUpForm
# Create your views here.

def SignUp(request):
    if request.method == 'POST':
        form = UserSignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f'your account has be created ! Now Log In{username}!')
            return redirect('login')
    else:
        form = UserSignUpForm()
    return render(request, 'forms/SignUp.html' , {'form' : form})

I've seen a lot of tutorials and they're doing the same thing

Typo of class Mate : in UserSignUpForm . It should be class Meta :

class UserSignUpForm(UserCreationForm):
    email = forms.EmailField()
    first_name = forms.CharField(max_length=50)
    last_name = forms.CharField(max_length=50)

    class Meta :
        model = User
        fields = ['username' , 'email' , 'first_name' , 'last_name' ,'password1' , 'password2']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM