try the code below
@login_required
def about(request):
# i think you don't need 'data' and thus pass it in the context with 'form'
# data= userdata.objects.all()
if request.method =='POST': # POST request
form=student(request.POST)
if form.is_valid():
name = request.POST.get('name')
email= request.POST.get('email')
password = request.POST.get('password')
fm = userdata(name=name,email=email,password=password)
fm.save()
# Add flash message and then redirect
messages.success(request, 'SUCCESS !')
return redirect(reverse_lazy('home'))
else:
messages.error(request, 'Please correct the errors below.')
# if 'form.is_valid()' return false you will get all errors in 'form.errors' bag
else: # GET request
form=student()
return render(request,'about.html',{'form':form})
refer to :
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…